rivr integration for the peewee database ORM.
$ pip install rivr-peewee
from rivr_peewee import Database
You can create a database with the DATABASE_URL
environment variable using the following:
database = Database()
Or you can provide a specific environmental variable to use, and/or a default database URL:
database = Database(env='DATABASE_URL',
default='sqlite:///Users/kylef/database.sqlite')
You can also explicitly create a database and use it as follows:
database = Database(peewee.SqliteDatabase(':memory:'))
The database object has a Model property to use as a base class for your models:
class User(database.Model):
pass
The database object itself is a rivr middleware which handles connecting and disconnecting to the database.
You can wrap a specific view in this:
app = database(router)
Or via a decorator:
@database
def view(request):
return Response('Hello World')
You can also use rivr’s middleware controller:
from rivr.middleware import MiddlewareController
app = MiddlewareController.wrap(router,
database,
ExampleMiddleware(),
)
rivr-peewee is released under the BSD license. See LICENSE.