sqlalchemy中打印建表语句

现在uliweb已经支持通过sql或sqltable显示建表语句,同时可以将创建索引语句也打印出来。主要使用了sqlalchemy.schema中的CreateTable()和CreateIndex()。简单的代码如下,假设table为Table对象:

print "%s;" % str(CreateTable(t)).rstrip()
for x in t.indexes:
    print "%s;" % CreateIndex(x)

你可能感兴趣的:(sqlalchemy中打印建表语句)