Muffin框架的Peewee-AIO集成
项目描述
muffin-peewee-aio – Peewee ORM集成到Muffin框架。
需求
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 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 966ed0661c19582d0e7359ec8e7ca29c897bf4dbfad1dd5ecec3e79852835581 |
|
MD5 | c8e24423173f288c51e3b00854b65cc4 |
|
BLAKE2b-256 | 2fed6065671a0a05303231914d2f2deccd742825c0811d6a469b5546ada7209d |
关闭
muffin_peewee_aio-0.18.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a308071b7526dbad27f60a0ee9284cd09bae6187cb15e663cf523d4307abc8b3 |
|
MD5 | c6fa2be237efb6af6fa50e48d27cf8a1 |
|
BLAKE2b-256 | e477a561ced247a3679838891ccd4282456c9426f9737485a2fefffbc8e15e87 |