GithubHelp home page GithubHelp logo

muffin-peewee's Introduction

Muffin Peewee

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

Tests Status

PYPI Version

Python Versions

Requirements

  • python >= 3.7

Installation

Muffin Peewee should be installed using pip: :

pip install muffin-peewee

Optionally you are able to install it with postgresql drivers: :

pip install muffin-peewee[postgres]

Usage

from muffin import Application
from muffin_peewee import Plugin as Peewee

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

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

Options

Name Default value Desctiption
CONNECTION sqlite+async:///db.sqlite Database URL
CONNECTION_PARAMS {} Additional params for DB connection
MANAGE_CONNECTIONS True Install a middleware to aquire db connections automatically
MIGRATIONS_ENABLED True Enable migrations with
MIGRATIONS_PATH "migrations" Set path to the migrations folder

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

Queries

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


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

Manage connections

# Set configuration option `MANAGE_CONNECTIONS` to False

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

Migrations

Create migrations: :

$ muffin example:app pw_create [NAME] [--auto]

Run migrations: :

$ muffin example:app pw_migrate [NAME] [--fake]

Rollback migrations: :

$ muffin example:app pw_rollback [NAME]

List migrations: :

$ muffin example:app pw_list

Bug tracker

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

Contributing

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

Contributors

  • klen (Kirill Klenov)

License

Licensed under a MIT license.

muffin-peewee's People

Contributors

dependabot[bot] avatar ei-grad avatar klen avatar lowks avatar ly0 avatar pyup-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lowks ei-grad ly0

muffin-peewee's Issues

Async queries

Hi @klen!

It's not really an issue report but a question. I see that db connections are handled asynchronously- that's great but I don't see anywhere that you await db queries- are they synchronous? I'm curious mostly because of benchmark that you made- seems cool but I'd like to understand why ?sync? queries doesn't choke the app.

Cheers!

Issue on tests.py causing errors on muffin tests

Hey,
i've made a pull request to muffin and its tests have not passed. Taking a look at the log files on travis i saw an issue on muffin-peewee which it was caused by a connection opening and peewee tells that it was already opened.

Below the stack trace:

―――――――――――――――――――――――――――――― test_async_peewee ―――――――――――――――――――――――――――――――
app = <Application: peewee>, model = <class 'tests.model.<locals>.Test'>
    @pytest.mark.async
    def test_async_peewee(app, model):
>       conn = yield from app.ps.peewee.database.async_connect()
tests.py:121: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
muffin_peewee/mpeewee.py:131: in async_connect
    self.connect()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <muffin_peewee.mpeewee.AIOSqliteExtDatabase object at 0x2b7ee1c842e8>
    def connect(self):
        with self._conn_lock:
            if self.deferred:
                raise OperationalError('Database has not been initialized')
            if not self._local.closed:
>               raise OperationalError('Connection already open')
E               peewee.OperationalError: Connection already open
/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/peewee.py:3652: OperationalError
 tests.py ✓✓✓⨯                                                   100% ██████████
!!!!!!!!!!!!!!!!!!!! Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!

Асинхронное выполнение запросов

В демо-приложении в основном репо был пример с асинхронным выполнением запросов к БД. В muffin_peewee.plugin.Plugin методы query и run закомментированы. Почему?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.