如何在tortoise-orm中运行连接数据库和执行查询的简单脚本
发布于 2020-05-14 05:42:59
如果你正在运行一个简单的脚本,你可以这样做,
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是一个辅助函数,用于运行简单的异步乌龟脚本。如果你正在运行乌龟ORM作为服务的一部分,请从乌龟orm文档中正确地看一下The Importance of cleaning up。
https://stackoverflow.com/questions/61785379
复制相似问题