Last active
August 30, 2019 09:41
-
-
Save robcowie/ad8766b3fa209c1b22578059d22345ff to your computer and use it in GitHub Desktop.
Print create SQL statement for tales and indices defined with SQLAlchemy
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
from sqlalchemy import create_engine, Table, MetaData | |
from sqlalchemy.schema import CreateIndex, CreateTable | |
metadata = MetaData() | |
engine = create_engine('') | |
def create_table_statement(connection, table): | |
stmts = [] | |
stmts.append(CreateTable(table).compile(connection)) | |
for index in table.indexes: | |
stmts.append(CreateIndex(index).compile(connection)) | |
return stmts | |
for s in create_table_statement(engine, my_table): | |
print(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment