Skip to content

Commit

Permalink
Merge pull request #5 from MitchellWeg/add_relationships
Browse files Browse the repository at this point in the history
Add relationships
  • Loading branch information
MitchellWeg authored Apr 5, 2022
2 parents 70172c7 + c9c9cc8 commit 653a66b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions examples/demo_monetdb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pymonetdb

import pyschemer
from pyschemer.schemer import Database

class Monet(Database):
Expand Down Expand Up @@ -32,7 +31,10 @@ def describe_tables(self):
self.tables = all_tables

def get_relationships(self, q=None):
return []
q = """
SELECT fk, fk_t, fk_c, pk_t, pk_c FROM describe_foreign_keys;
"""
return super().get_relationships(q)

def main():
conn = pymonetdb.connect(
Expand Down
7 changes: 7 additions & 0 deletions pyschemer/relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@ def __init__(
self.referenced_table_name = ref_table
self.referenced_column_name = ref_column

def __repr__(self) -> str:
return "".join([
f"{self.table_name}:{self.column_name}",
" 1--* ",
f"{self.referenced_table_name}:{self.referenced_column_name}"
])

def to_json(self):
return self.__repr__()
2 changes: 1 addition & 1 deletion pyschemer/schemer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_dot(self):

def draw(self, dot_code, filename='out'):
G = pgv.AGraph(string=dot_code)
schema_drawing = G.draw(path=None, format='jpeg', prog='dot')
schema_drawing = G.draw(path=None, format='jpeg', prog='circo')

with open(f'{filename}.jpg', 'wb') as outfile:
outfile.write(schema_drawing)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='pyschemer',
version='1.0.2',
version='1.1.0',
description='A database visualization tool',
url='https://github.com/MitchellWeg/schemer',
author='Mitchell Weggemans',
Expand All @@ -20,7 +20,7 @@
],

classifiers=[
'Development Status :: 1 - Planning',
'Development Status :: 4 - Beta',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX :: Linux',
Expand Down

0 comments on commit 653a66b

Please sign in to comment.