On 2/10/11 6:40 PM, Christopher Weimann wrote:
I'm using DB-API in my Pylons app as described in on this wiki page.
http://wiki.pylonshq.com/display/pylonscookbook/Using+the+DB-API+in+Pylons
The gist of which is to add the following to lib/app_globals.py
from pylons import config
import psycopg2
from DBUtils.PooledDB import PooledDB
class Globals(object):
def __init__(self):
self.pool = PooledDB( psycopg2, 5,
database=config['app_conf']['pool.database'],
user=config['app_conf']['pool.user'],
host=config['app_conf']['pool.host']
)
then in a controller you can get a connection with conn = g.pool.connection()
How would I do the equivalent with Pyramid?
This is untested, but i think you could do something like this in your
startup code::
from pyramid.registry import global_registry
global_registry.pool = PooledDB(...)
Then in your view code, or anywhere you have a request object, you
should be able to get at it via `request.registry.pool`.
-r
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.