- Pronouns: he/him
fschulze / sqlalchemy_schemadisplay Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
It would be useful if the display used the standard crows foot notation, eg as per https://www.codeproject.com/Articles/878359/Data-modelling-using-ERD-with-Crow-Foot-Notation .
def graphviz_crow_arrowheads( cardinality):
if cardinality=='*': # *: {0..N}
head='crowodot'
elif cardinality=='?': # ?: {0,1}
head='teeodot'
elif cardinality=='+': # +: {1,N}
head='crowtee'
elif cardinality=='1': # 1: {1}
head='teetee'
return head
Should table nodes be grouped by schema when schema is provided? I think graphviz supports subgraphs and clusters that would accommodate this capability. Depending on the layout engine chosen it would manifest in the diagram or not.
This should migrate to README.
It would be great to have sqlalchemy_schemadisplay render final image inside Jupyter Notebook.
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).
These function import cStringIO
, which is not available on python3.x and hence, they fail.
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
Who would like to take over maintenance of this project? I don't have the interest and time to do it anymore.
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?
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/SchemaDisplay on front page and PyPI gives 404.
Some output examples would not hurt.
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.
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
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
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```
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.