PylonsHQ.

Layout: Fixed-width

Using Schevo databases with Pylons

(currently incomplete -- moving this information from other sources) 

Using SchevoWsgi

The "SchevoWsgi" package provides an ability to expose one or more databases to a WSGI environment by way of a Paste filter called dbopener.

SchevoWsgi is usually preferred since it lets you use the same Schevo database in more than one WSGI application if you've composited them together.

To use it with a Pylons app, first edit your setup.py file and add "SchevoWsgi==dev" to your install_requires list.

Next, edit your development.ini file. Add these two sections below [DEFAULT], where yourapp is the unique name of your application:

[pipeline:main]
pipeline = dbopener yourapp

[filter:dbopener]
use = egg:SchevoWsgi#dbopener
schevo.db.db = %(here)s/dev.db
verbose = true

Change the [app:main] section name to [app:yourapp], to disambiguate it from the pipeline whose name is main.
Now, provided you have a dev.db Schevo database in the same directory as your development.ini file, it will open it when you serve up the development.ini application.

It is useful to expose the open database more easily by referring to self.db in controller code. To enable this, open yourapp/lib/base.py and add this line above the return statement in the BaseController.__call__ method:

self.db = environ['schevo.db.db']

Without using SchevoWsgi

Edit your development.ini file. In the [app:main] section, add the following line:

schevo.db = %(here)s/dev.db

In your models/__init__.py file, open the database:

from paste.deploy.config import CONFIG
from schevo import database

db = database.open(CONFIG['app_conf']['schevo.db'])

You can now access the open Schevo database as model.db in your controller code.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jun 06, 2007

    Yury Yurevich says:

    I'm using such setup without SchevoWsgi: Add this line to development.ini # Sc...

    I'm using such setup without SchevoWsgi:

    Add this line to development.ini

    # Schevo DB instance in app section in .ini
    schevo.db = %(here)s/dev/db

    and then, in models/_init_.py:

    from paste.deploy.config import CONFIG
    from schevo import database
    
    db = database.open(CONFIG['app_conf']['schevo.db'])

    Schevo DB instance is accessible as model.db in controllers.

  2. Jun 06, 2007

    Matthew Scott says:

    Yury, thanks for the comment. I'll definitely incorporate that information into...

    Yury, thanks for the comment. I'll definitely incorporate that information into the main page soon. The method you are using is fine, and is what I used to use actually. One reason for using SchevoWsgi is if you want to use the same Schevo database across more than one WSGI app where those apps have been composited together. I'll make sure to note that in the main page as well to help people decide between the two approaches.

  3. Feb 20, 2008

    James Su says:

    I'd like to divide code to model.domains, so I put you models/_init.py codes to ...

    I'd like to divide code to model.domains, so I put you models/_init.py codes to models/schevodb.py, and import db object in every domain and/or __init_.py as needed:
    from app.model.schevodb import db


Powered by Pylons - Contact Administrators