[Twisted-Python] psycopg2 and dictcursor

Federico Di Gregorio fog at initd.org
Mon Apr 24 13:50:00 MDT 2006


Il giorno lun, 24/04/2006 alle 15.13 -0400, Jonathan Vanasco ha scritto:
> Hi all
> 
> I'm picking up twisted again ( haven't touched it for a while )
> 
> Luckily twisted plays great with psycopg2
> 
> I really prefer using the dictcursor in psycopg2 though:

I use a "fake" dbapi module that wraps psycopg 2 and import it by giving
its name to the adbapi connection pool. Something like (let's suppose we
put it in a twistedpg.py module):

"""
from psycopg2 import *
from psycopg2 import _psycopg as _2psycopg
from psycopg2.extensions import connection as _2connection
from psycopg2.extras import DictCursor

del connect
def connect(*args, **kwargs):
    kwargs['connection_factory'] = connection
    return _2psycopg.connect(*args, **kwargs)

class connection(_2connection):
    def cursor(self):
        return _2connection.cursor(self, cursor_factory=DictCursor)
"""

Then:

"""
from twisted.enterprise import adbapi

mypool = adbapi.ConnectionPool("twistedpg", database="xxx", ...)
"""

Hope this helps,
federico

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                fog at debian.org
INIT.D Developer                                           fog at initd.org
                   I came like Water, and like Wind I go. -- Omar Khayam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Questa รจ una parte del messaggio	firmata digitalmente
URL: </pipermail/twisted-python/attachments/20060424/457251f9/attachment.sig>


More information about the Twisted-Python mailing list