如何在tortoise-orm中运行连接db并执行查询的简单脚本?
如果您运行的是简单脚本,则可以执行此操作,
from tortoise import Tortoise
async def init():
# Here we create a SQLite DB using file "db.sqlite3"
# also specify the app name of "models"
# which contain models from "app.models"
await Tortoise.init(
db_url='sqlite://db.sqlite3',
modules={'models': ['app.models']}
)
# Generate the schema (run this only if you need to generate the schema)
# await Tortoise.generate_schemas()
run_async(init())
run_async
是运行简单异步Tortoise脚本的辅助功能。如果您正在将Tortoise ORM作为服务的一部分运行,请查看正确清理Tortise orm文档的重要性。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句