Skip to content

Peewee integration to Muffin framework with async support

Notifications You must be signed in to change notification settings

klen/muffin-peewee-aio

Repository files navigation

Muffin Peewee AIO

muffin-peewee-aio -- Peewee ORM integration to Muffin framework.

Tests Status PYPI Version Python Versions
  • python >= 3.9

Muffin Peewee should be installed using pip:

$ pip install muffin-peewee-aio

You can install optional database drivers with:

$ 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')
Name Default value Desctiption
CONNECTION sqlite:///db.sqlite Database URL
CONNECTION_PARAMS {} Additional params for DB connection
AUTO_CONNECTION True Automatically get a connection from db for a request
AUTO_TRANSACTION True Automatically wrap a request into a transaction
MIGRATIONS_ENABLED True Enable migrations with
MIGRATIONS_PATH "migrations" Set path to the migrations folder
PYTEST_SETUP_DB True Manage DB schema and connection in pytest

You are able to provide the options when you are initiliazing the plugin:

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

Or setup it inside Muffin.Application config using the PEEWEE_ prefix:

PEEWEE_CONNECTION = 'DB_URL'

Muffin.Application configuration options are case insensitive

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
        # ...

Create migrations:

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

Run migrations:

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

Rollback migrations:

$ muffin example:app peewee-rollback [NAME]

List migrations:

$ muffin example:app peewee-list

Clear migrations from DB:

$ muffin example:app peewee-clear

Merge migrations:

$ muffin example:app peewee-merge

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/muffin-peewee-aio/issues

Development of Muffin Peewee happens at: https://github.com/klen/muffin-peewee-aio

  • klen (Kirill Klenov)

Licensed under a MIT license.

About

Peewee integration to Muffin framework with async support

Topics

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published