rhino.ext.sqlalchemy
This module contains a SessionProperty class that can be used to add a SQLALchemy Session object to the context.
This extension requires the SQLAlchemy module to be installed:
$ pip install sqlalchemy
The session is lazily initialized and closed at the end of every request.
Example usage:
from rhino import Mapper, get
from rhino.ext.sqlalchemy import SessionProperty
from models import Movie # module containing SQLAlchemy ORM classes
app = rhino.Mapper()
app.add_ctx_property('db', SessionProperty('sqlite:///db.sqlite'))
@get
def index(request, ctx):
movies = ctx.db.query(Movie).all()
# ...
app.add('/', index)
class SessionProperty
__init__(url=None, delay_close=False, **session_args)