Re: flexi adaption/casting scheme - Mailing list psycopg

From Tobias Oberstein
Subject Re: flexi adaption/casting scheme
Date
Msg-id 505C765E.8060308@gmail.com
Whole thread Raw
In response to Re: flexi adaption/casting scheme  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
List psycopg
Hi Daniel,

thanks for your hints .. I have learned some things!

>> Above should work with nested PG types (array of composite type with
>> an attribute again composite type etc etc).
>
> The composite caster already deals correctly with nested types: the
> change to make it return dicts instead of tuples should be a few lines
> of code.

Apparently I failed to articulate what I try to do: yes, adjusting
the CompositeCaster to _return_ dicts instead of tuples is a snap
replacing

         return self._ctor(*attrs)

with

         for i in xrange(len(self.atttypes)):
             if attrs[i] is not None:
                 o[self.attnames[i]] = attrs[i]
         return o

in CompositeCaster.parse.

(sidenote: somewhat inconvenient is the fact that I need to duplicate
the code .. cannot derive from the class, since the
CompositeCaster._from_db class method will always construct a
CompositeCaster, not my derived class).

What I am struggling with is the _opposite_ direction: have Python
dicts automatically adapt to composite types (when knowing the
respective target type).

In the meantime I have gotten quite close:

https://github.com/oberstet/scratchbox/blob/master/python/psycopg2/test6.py

Nested arrays of composite types still don't work ..

Cheers,
Tobias


psycopg by date:

Previous
From: Ronan Dunklau
Date:
Subject: Re: flexi adaption/casting scheme
Next
From: Tobias Oberstein
Date:
Subject: Re: flexi adaption/casting scheme