跳转到主要内容

Muffin框架的Peewee-AIO集成

项目描述

muffin-peewee-aioPeewee ORM集成到Muffin框架。

Tests Status PYPI Version Python Versions

需求

  • python >= 3.9

安装

Muffin Peewee应使用pip安装

$ pip install muffin-peewee-aio

您可以使用以下命令安装可选的数据库驱动程序

$ pip install muffin-peewee-aio[aiosqlite]
$ pip install muffin-peewee-aio[aiopg]
$ pip install muffin-peewee-aio[asyncpg]
$ pip install muffin-peewee-aio[aiomysql]

用法

from muffin import Application
from muffin_peewee import Plugin as Peewee

# Create Muffin Application
app = Application('example')

# Initialize the plugin
# As alternative: db = Peewee(app, **options)
db = Peewee()
db.setup(app, PEEWEE_CONNECTION='postgresql://postgres:postgres@localhost:5432/database')

选项

名称

默认值

描述

CONNECTION

sqlite:///db.sqlite

数据库URL

CONNECTION_PARAMS

{}

DB连接的额外参数

AUTO_CONNECTION

True

自动从db获取请求的连接

AUTO_TRANSACTION

True

自动将请求包装在事务中

MIGRATIONS_ENABLED

True

启用迁移

MIGRATIONS_PATH

"migrations"

设置迁移文件夹的路径

PYTEST_SETUP_DB

True

在pytest中管理DB模式和连接

您可以在初始化插件时提供选项

db.setup(app, connection='DB_URL')

或使用Muffin.Application配置中的PEEWEE_前缀在内部设置

PEEWEE_CONNECTION = 'DB_URL'

Muffin.Application配置选项不区分大小写

查询

class Test(db.Model):
    data = peewee.CharField()


@app.route('/')
async def view(request):
    return [t.data async for t in Test.select()]

管理连接

# Set configuration option `MANAGE_CONNECTIONS` to False

# Use context manager
@app.route('/')
async def view(request):
    # Aquire a connection
    async with db.manager.connection():
        # Work with db
        # ...

迁移

创建迁移

$ muffin example:app peewee-create [NAME] [--auto]

运行迁移

$ muffin example:app peewee-migrate [NAME] [--fake]

回滚迁移

$ muffin example:app peewee-rollback [NAME]

列出迁移

$ muffin example:app peewee-list

从DB中清除迁移

$ muffin example:app peewee-clear

合并迁移

$ muffin example:app peewee-merge

错误跟踪器

如果您有任何建议、错误报告或烦恼,请向问题跟踪器报告,链接为:https://github.com/klen/muffin-peewee-aio/issues

贡献

Muffin Peewee 的开发发生在这里:https://github.com/klen/muffin-peewee-aio

贡献者

  • klen (Kirill Klenov)

许可

在 MIT 许可证下发布。

项目详情


下载文件

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

源分发

muffin_peewee_aio-0.18.0.tar.gz (6.6 kB 查看哈希值)

上传时间

构建分发

muffin_peewee_aio-0.18.0-py3-none-any.whl (7.1 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWSAWS 云计算和安全赞助商 DatadogDatadog 监控 FastlyFastly CDN GoogleGoogle 下载分析 MicrosoftMicrosoft PSF赞助商 PingdomPingdom 监控 SentrySentry 错误记录 StatusPageStatusPage 状态页面