从引擎开始:
from sqlalchemy import create_engineengine = create_engine("postgresql://u:p@host/database")
from sqlalchemy import inspectinspector = inspect(engine)for table_name in inspector.get_table_names(): for column in inspector.get_columns(table_name): print("Column: %s" % column['name'])
docs:http :
//docs.sqlalchemy.org/zh/rel_0_9/core/reflection.html? highlight=
inspector# fine-grained-reflection-with-
inspector
或者,使用元数据/表:
from sqlalchemy import metaDatam = metaData()m.reflect(engine)for table in m.tables.values(): print(table.name) for column in table.c: print(column.name)
docs:http :
//docs.sqlalchemy.org/en/rel_0_9/core/reflection.html#reflecting-all-tables-
at-
once
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)