def main(filename):
    """
    Generate an entity-relationship diagram for the given database.

    filename must be the path to a JSON Table Schema file
    """
    relation_regexps = [
        '(^| )[Rr]ef to ',
        '(^| )[Rr]eference( to|s) ',
    ]
    exclude_tables_regexps = [
        '^tmp_.*$',
        '^temp_.*$',
        '^loc_.*$',
        '^tmp1_.*$',
        '^unused_.*$',
        '^studytmp_.*$',
    ]

    with open(filename, 'r') as f:
        j = json.load(f)

    notifications = []
    from pprint import pprint as print_
    print_(j, width=200)
    jts_erd.save_svg(
        j,
        'jts_erd_tmp.svg',
        display_columns=True,
        display_indexes=True,
        rankdir='RL',
    )
    for n in notifications:
        print(n[0], n[1])
def main(db_conn_str):
    """
    Generate an entity-relationship diagram for the given database.

    *db_conn_str* must be a valid PostgreSQL connect string.
    """
    relation_regexps = [
        '(^| )[Rr]ef to ',
        '(^| )[Rr]eference( to|s) ',
    ]
    exclude_tables_regexps = [
        '^tmp_.*$',
        '^temp_.*$',
        '^loc_.*$',
        '^tmp1_.*$',
        '^unused_.*$',
        '^studytmp_.*$',
    ]
    if db_conn_str:
        json_database_schema, notifications = pg_jts.get_database(
            db_conn_str,
            relation_regexps=relation_regexps,
            exclude_tables_regexps=exclude_tables_regexps)
        j = json.loads(json_database_schema)
    else:
        j = default_database
        notifications = []
    from pprint import pprint as print_
    print_(j, width=200)
    jts_erd.save_svg(
        j,
        '/tmp/jts_erd_tmp.svg',
        display_columns=True,
        display_indexes=True,
        omit_isolated_tables=True,
        rankdir='RL',
    )
    for n in notifications:
        print(n[0], n[1])
示例#3
0
def main(db_conn_str):
    """
    Generate an entity-relationship diagram for the given database.

    *db_conn_str* must be a valid PostgreSQL connect string.
    """
    relation_regexps = ["(^| )[Rr]ef to ", "(^| )[Rr]eference( to|s) "]
    exclude_tables_regexps = ["^tmp_.*$", "^temp_.*$", "^loc_.*$", "^tmp1_.*$", "^unused_.*$", "^studytmp_.*$"]
    if db_conn_str:
        json_database_schema, notifications = pg_jts.get_database(
            db_conn_str, relation_regexps=relation_regexps, exclude_tables_regexps=exclude_tables_regexps
        )
        j = json.loads(json_database_schema)
    else:
        j = default_database
        notifications = []
    from pprint import pprint as print_

    print_(j, width=200)
    jts_erd.save_svg(
        j, "/tmp/jts_erd_tmp.svg", display_columns=True, display_indexes=True, omit_isolated_tables=True, rankdir="RL"
    )
    for n in notifications:
        print(n[0], n[1])
示例#4
0
import sys
sys.path.append('..')
dsn = sys.argv[1]

import pg_jts

j, notifications = pg_jts.get_database(dsn)

from pprint import pprint as print_
import json

print_(json.loads(j), width=200)
示例#5
0
    NOT IMPLEMENTED; TODO:
    """
    q = """
    SELECT  proname, prosrc
    FROM    pg_catalog.pg_namespace n
    JOIN    pg_catalog.pg_proc p
    ON      pronamespace = n.oid
    WHERE   nspname = 'public';
    """


if __name__ == '__main__':
    from postgres_access import init
    init()
    from pprint import pprint as print_
    print_(get_schemas())
    for schema in get_schemas():
        print_(schema)
        schema_name = schema['schema_name']
        for table in get_tables(schema_name):
            print_(table)
            table_name = table['table_name']
            for column in get_columns(schema_name, table_name):
                print_(column)
            print(get_indexes(schema_name, table_name))
        for view in get_views(schema_name):
            print(view)
            # print(get_indexes(schema_name, table_name)))
    print()
    print(get_table_columns())
示例#6
0
    NOT IMPLEMENTED; TODO:
    """
    q = """
    SELECT  proname, prosrc
    FROM    pg_catalog.pg_namespace n
    JOIN    pg_catalog.pg_proc p
    ON      pronamespace = n.oid
    WHERE   nspname = 'public';
    """


if __name__ == '__main__':
    from postgres_access import init
    init()
    from pprint import pprint as print_
    print_(get_schemas())
    for schema in get_schemas():
        print_(schema)
        schema_name = schema['schema_name']
        for table in get_tables(schema_name):
            print_(table)
            table_name = table['table_name']
            for column in get_columns(schema_name, table_name):
                print_(column)
            print(get_indexes(schema_name, table_name))
        for view in get_views(schema_name):
            print(view)
            # print(get_indexes(schema_name, table_name)))
    print()
    print(get_table_columns())