开发者

Use raw SQL to create tables in SQLAlchemy, after which use ORM

开发者 https://www.devze.com 2022-12-15 12:43 出处:网络
Is it possible to use raw SQL rather than the TABLE construct for creating tables in SQL Alchemy?I would still like to use the rest of SQLAlchemy though, such as the object mapper and session module.I

Is it possible to use raw SQL rather than the TABLE construct for creating tables in SQL Alchemy? I would still like to use the rest of SQLAlchemy though, such as the object mapper and session module. I'm just not fond of the SQLAlchemy syntax used to create开发者_高级运维 tables (I've spent too long mired in SAS and SQL to learn another!).

Many thanks, Rich


Yes.

connection.execute("""
CREATE TABLE ...
""")

You can then reflect all tables: MetaData(dsn, reflect=True) or metadata_instance.reflect().


You can use the autoload paramater to the Table constructor to have it automatically load up the table definitions. There are some examples here.

0

精彩评论

暂无评论...
验证码 换一张
取 消