首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用tortoise-orm运行简单的脚本?

如何使用tortoise-orm运行简单的脚本?
EN

Stack Overflow用户
提问于 2020-05-14 05:42:59
回答 1查看 491关注 0票数 1

如何在tortoise-orm中运行连接数据库和执行查询的简单脚本

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-14 05:42:59

如果你正在运行一个简单的脚本,你可以这样做,

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61785379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档