查看文章 |
How to display table creation SQL statement in SQLAlchemy
2009-02-04 12:01
I asked this question in sqlalchemy mail list, and got the answer, you can find in sqlalchemy FAQ. I copied the example in here: from sqlalchemy import * from StringIO import StringIO buf = StringIO() engine = create_engine('postgres://', strategy='mock', executor=lambda s, p='': buf.write(s + p)) meta = MetaData() t1 = Table('sometable', meta, Column('foo', String(30))) meta.create_all(engine) print buf.getvalue() The most important thing in above example is the create_engine invoking. The example uses 'postgress://', and I've tested it with 'sqlite://', and it's different in some column definition. And the strategy='mock' will prevent the tables creation exactly. So with this help I also added an 'sql' command in Uliweb, so that you can see the creation SQL. |
最近读者:
