跳转到主要内容

Quart-DB 是一个 Quart 扩展,它提供对数据库的托管连接。

项目描述

Build Status docs pypi python license

Quart-DB 是一个 Quart 扩展,它提供对 PostgreSQL 或 SQLite 数据库的托管连接。

快速入门

Quart-DB 通过将其与一个应用和数据库(通过 URL)关联,并利用 g.connection 连接来使用。

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 = :done", {"done": True})
        ...
    return {}

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

贡献

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

测试

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

$ pip install tox
$ tox

这将检查代码风格并运行测试。

帮助

Quart-DB的文档是开始的好地方,之后尝试在Stack Overflow搜索或在Gitter上寻求帮助。如果您仍然找不到答案,请打开一个问题

项目详情


下载文件

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

源代码分发

quart_db-0.8.3.tar.gz (11.6 kB 查看哈希)

上传时间 源代码

构建分发

quart_db-0.8.3-py3-none-any.whl (13.3 kB 查看哈希)

上传时间 Python 3

由以下赞助

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面