Last active
July 6, 2021 16:10
-
-
Save Kulasangar/038b44a1621b88d128c4e6610daf4f05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from schemacrawler.schema import TableRelationshipType # pylint: disable=import-error | |
print(catalog.crawlInfo) | |
tables = {} | |
for table in catalog.tables: | |
col_list = [] | |
columns = {} | |
pk = '' | |
print('') | |
print(table.fullName) | |
for column in table.getColumns(): | |
column_metadata = {} | |
print('column -> {}'.format(column)) | |
print('data type -> {}'.format(column.getColumnDataType())) | |
print('length -> {}'.format(column.getSize())) | |
column_metadata['column'] = str(column.getName()) | |
column_metadata['data type'] = str(column.getColumnDataType()) | |
column_metadata['length'] = str(column.getSize()) | |
col_list.append(column_metadata) | |
if column.isPartOfPrimaryKey(): | |
pk = column.getName() | |
print('Primary key is - {} '.format(column.getName())) | |
for childTable in table.getRelatedTables(TableRelationshipType.child): | |
print(" [child is] " + childTable.fullName) | |
columns['columns'] = col_list | |
columns['primary_key'] = pk | |
tables[str(table.getName())] = columns | |
with open('tables.json', 'w') as f: | |
json.dump(tables, f, ensure_ascii=False, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment