[Twisted-Python] mapped resultsets for adbapi: "runQueryMapped"

James Y Knight foom at fuhm.net
Fri Jun 4 11:22:10 EDT 2004

I'll note that you don't actually have to change adbapi in order to do 
this. See the "runInteraction" method call.

You would do something like:
def mapQuery(curs, *args, **kwargs):
  curs.execute(*args, **kwargs)
  result = curs.fetchall()
  columns = [d[0] for d in curs.description]
  return [dict(zip(columns, r)) for r in result]

dbpool.runInteraction(mapQuery, ...)


On Jun 4, 2004, at 4:29 AM, Federico Di Gregorio wrote:

> Lì venerdì, 2004/06/04 alle 02:33, -0400, Stephen Waterbury ha scritto:
>> Gang,
>> I don't know whether this is of interest to anyone else, but
>> I needed it for my stuff and I was hoping it might be suitable for
>> inclusion in adbapi:  it defines a new adbapi.ConnectionPool method
>> called 'runQueryMapped' (and corresponding '_runQueryMapped') whose
>> return value is a list of dicts that map column names to values
>> (rather than the list of lists of values that runQuery returns).
> i think it is a usefull addition.
> federico
> -- 
> Federico Di Gregorio                         
> http://people.initd.org/fog
> Debian GNU/Linux Developer                                
> fog at debian.org
> INIT.D Developer                                           
> fog at initd.org
>   We are all dust, Saqi, so play the lute
>                     We are all wind, Saqi, so bring wine. -- Omar 
> Khayam
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

More information about the Twisted-Python mailing list