Giter Club home page Giter Club logo

sqlalchemy_schemadisplay's Introduction

Hi!

  • Pronouns: he/him

sqlalchemy_schemadisplay's People

Contributors

abitrolly avatar ben-muller avatar bkrn avatar cchrysostomou avatar electrocucaracha avatar fschulze avatar gheritarish avatar kajuberdut avatar lincrosenbach avatar ragingroosevelt avatar surgo avatar tiagosab avatar zlopez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlalchemy_schemadisplay's Issues

Display table's schema in diagram

If the metadata for the declarative base doesn't include a schema but schema is specified for each table, it is possible that different tables will have different schemas:

from sqlalchemy import MetaData
from sqlalchemy.ext.declarative import declarative_base

meta_data = MetaData()
dec_base = declarative_base(metadata=meta_data)

schemaA = {"schema": "schema_a"}
schemaB = {"schema": "schema_b"}

class Tab_A(dec_base):
    __tablename__ = 'tab_a'
    __table_args__ = (schemaA , )
    ...

class Tab_B(dec_base):
    __tablename__ = 'tab_b'
    __table_args__ = (schemaB , )
    ...

class Tab_C(dec_base):
    __tablename__ = 'tab_c'
    __table_args__ = (schemaB , )
    ...

In such a scenario, it would be nice to be able to view schemas when generating the diagram:

from sqlalchemy_schemadisplay import create_schema_graph
graph = create_schema_graph(metadata=meta_data)

Conceivably, it could be handy to also be able to either specify a per-schema color for the border of each of the member tables, or to place all the tables for a particular schema within a rectangle for that schema (where you could have a different background color for each of the containing rectangles).

Show table docstrings in schema display

I would love it if a table declared as

class MyTable(BaseModel):
    """doc string explaining the table """
    field = Column(Integer)

would show the docstring in the diagram right under the name and before the fields

Maintenance

Who would like to take over maintenance of this project? I don't have the interest and time to do it anymore.

More flexibility to create_schema_graph

On my own fork I customized the code a little for our own aesthetic needs:
https://github.com/chunweiyuan/sqlalchemy_schemadisplay/blob/foreign_key_edges/sqlalchemy_schemadisplay.py#L171-L203

However, it does feel like we should avoid this type of hard-coding and allow create_schema_graph's API to take arguments for graphical tuning.

1.) Is there any plan to make create_schema_graph more flexible for plotting?
2.) Running pytest in python 3.6 fails due to issues with StringIO and cStringIO. Should we make this thing 2/3 compatible?

Incompatible with SQLAlchemy 2.0.0

Today I got a automatic PR updating SQLAlchemy to 2.0.0 and the sqlalchemy_schemadisplay stopped working.

Here is the backtrace:

Traceback (most recent call last):
  File "/var/home/zlopez/git/anitya/docs/generate_db_schema", line 29, in <module>
    write_graph('images/database.png')
  File "/var/home/zlopez/git/anitya/docs/generate_db_schema", line 18, in write_graph
    graph = create_schema_graph(
  File "/var/home/zlopez/git/anitya/.tox/docs/lib/python3.10/site-packages/sqlalchemy_schemadisplay.py", line 153, in create_schema_graph
    label=_render_table_html(table, metadata, show_indexes, show_datatypes),
  File "/var/home/zlopez/git/anitya/.tox/docs/lib/python3.10/site-packages/sqlalchemy_schemadisplay.py", line 121, in _render_table_html
    if metadata.bind and isinstance(metadata.bind.dialect, PGDialect):
AttributeError: 'MetaData' object has no attribute 'bind'

The whole script for generation database schema could be found here.

Usage information?

Some usage information about this code would be useful, like an example or two. I currently have no idea how to use this code.

Regards, Faheem

FileNotFoundError: [WinError 2] The system cannot find the file specified

I'm connecting to a database using odbc using a guest database account and I keep getting file not found error. Any help would be appreciated.

Thanks

from sqlalchemy import MetaData
from sqlalchemy_schemadisplay import create_schema_graph

connection_string = ('Driver={SQL Server};'
            'Server=MYSERVER;'
            'Database=MYDATABASE;'
            'Trusted_Connection=no;'
            'UID=username;'
            'PWD=password;')


DATABASE_URL = URL.create("mssql+pyodbc", query={"odbc_connect": connection_string})

graph = create_schema_graph(metadata=MetaData(DATABASE_URL),
    show_datatypes=False,
    show_indexes=False,
    rankdir='LR', 
    concentrate=False
)
graph.write_png('dbschema.png')

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
[c:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\pydot.py](file:///C:/Users/AppData/Local/Programs/Python/Python37/lib/site-packages/pydot.py) in create(self, prog, format, encoding)
   1925                 arguments=arguments,
-> 1926                 working_dir=tmp_dir,
   1927             )

[c:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\pydot.py](file:///C:/Users/AppData/Local/Programs/Python/Python37/lib/site-packages/pydot.py) in call_graphviz(program, arguments, working_dir, **kwargs)
    138         stdout=subprocess.PIPE,
--> 139         **kwargs
    140     )

[c:\Users\AppData\Local\Programs\Python\Python37\lib\subprocess.py](file:///C:/Users/AppData/Local/Programs/Python/Python37/lib/subprocess.py) in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    799                                 errread, errwrite,
--> 800                                 restore_signals, start_new_session)
    801         except:

[c:\Users\AppData\Local\Programs\Python\Python37\lib\subprocess.py](file:///C:/Users/AppData/Local/Programs/Python/Python37/lib/subprocess.py) in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1206                                          os.fspath(cwd) if cwd is not None else None,
-> 1207                                          startupinfo)
   1208             finally:

FileNotFoundError: [WinError 2] The system cannot find the file specified

FileNotFoundError: [WinError 2] The system cannot find the file specified

I'm connecting to a database using odbc using a guest database account and I keep getting file not found error. Any help would be appreciated.

Thanks

from sqlalchemy_schemadisplay import create_schema_graph

connection_string = ('Driver={SQL Server};'
            'Server=MYSERVER;'
            'Database=MYDATABASE;'
            'Trusted_Connection=no;'
            'UID=username;'
            'PWD=password;')


DATABASE_URL = URL.create("mssql+pyodbc", query={"odbc_connect": connection_string})

graph = create_schema_graph(metadata=MetaData(DATABASE_URL),
    show_datatypes=False,
    show_indexes=False,
    rankdir='LR', 
    concentrate=False
)
graph.write_png('dbschema.png')

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
[c:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\pydot.py](file:///C:/Users/AppData/Local/Programs/Python/Python37/lib/site-packages/pydot.py) in create(self, prog, format, encoding)
   1925                 arguments=arguments,
-> 1926                 working_dir=tmp_dir,
   1927             )

[c:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\pydot.py](file:///C:/Users/AppData/Local/Programs/Python/Python37/lib/site-packages/pydot.py) in call_graphviz(program, arguments, working_dir, **kwargs)
    138         stdout=subprocess.PIPE,
--> 139         **kwargs
    140     )

[c:\Users\AppData\Local\Programs\Python\Python37\lib\subprocess.py](file:///C:/Users/AppData/Local/Programs/Python/Python37/lib/subprocess.py) in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    799                                 errread, errwrite,
--> 800                                 restore_signals, start_new_session)
    801         except:

[c:\Users\AppData\Local\Programs\Python\Python37\lib\subprocess.py](file:///C:/Users/AppData/Local/Programs/Python/Python37/lib/subprocess.py) in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1206                                          os.fspath(cwd) if cwd is not None else None,
-> 1207                                          startupinfo)
   1208             finally:

FileNotFoundError: [WinError 2] The system cannot find the file specified```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.