Latest Version: 0.9.6.2
  Dashboard > Pylons Cookbook > ... > Database > Using Schevo databases with Pylons
  Pylons Cookbook Log In | Sign Up   View a printable version of the current page.  
  Using Schevo databases with Pylons
Added by Matthew Scott, last edited by Matthew Scott on Jul 25, 2007  (view change)
Labels: 
(None)

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

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.

Posted by Yury Yurevich at Jun 06, 2007 03:03 | Permalink

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.

Posted by Matthew Scott at Jun 06, 2007 15:49 | Permalink

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

Posted by James Su at Feb 20, 2008 01:50 | Permalink
Site running on a free Atlassian Confluence Open Source Project License granted to Pylons. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.3.3 Build:#645 Feb 13, 2007) - Bug/feature request - Contact Administrators
Top