Re: flexi adaption/casting scheme

Поиск
Список
Период
Сортировка
От Tobias Oberstein
Тема Re: flexi adaption/casting scheme
Дата
Msg-id 505C765E.8060308@gmail.com
обсуждение исходный текст
Ответ на Re: flexi adaption/casting scheme  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Ronan Dunklau
Дата:
Сообщение: Re: flexi adaption/casting scheme
Следующее
От: Tobias Oberstein
Дата:
Сообщение: Re: flexi adaption/casting scheme