Skip to main content

Quart-DB 是一个 Quart 扩展,为 postgresql 数据库提供托管连接。

项目描述

构建状态 文档 皮皮 Python 执照

Quart-DB 是一个 Quart 扩展,为 postgresql 数据库提供托管连接。

快速开始

通过将 Quart-DB 与应用程序和数据库(通过 URL)相关联,然后利用g.connection连接来使用 Quart-DB,

from quart import g, Quart, websocket
from quart_db import QuartDB

app = Quart(__name__)
db = QuartDB(app, url="postgresql://user:pass@localhost:5432/db_name")

@app.get("/<int:id>")
async def get_count(id: int):
    result = await g.connection.fetch_val(
        "SELECT COUNT(*) FROM tbl WHERE id = :id",
        {"id": id},
    )
    return {"count": result}

@app.post("/")
async def set_with_transaction():
    async with g.connection.transaction():
        await db.execute("UPDATE tbl SET done = $1", [True])
        ...
    return {}

@app.get("/explicit")
async def explicit_usage():
     async with db.connection() as connection:
         ...

参数可以通过位置$1或关键字:id 绑定来定义。

贡献

Quart-DB 在GitHub 上开发。如果您遇到问题或有功能请求,请打开问题。如果您想提供修复或功能实现,请通过提出合并请求(欢迎修复拼写错误) 。

测试

测试 Quart-DB 的最佳方法是使用Tox

$ pip install tox
$ tox

这将检查代码样式并运行测试。

帮助

Quart-DB文档是最好的起点,之后尝试搜索堆栈溢出在 gitter 上寻求帮助。如果您仍然找不到答案,请打开一个问题

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

quart-db-0.3.0.tar.gz (9.2 kB 查看哈希)

已上传 source

内置分布

quart_db-0.3.0-py3-none-any.whl (8.5 kB 查看哈希

已上传 py3