Re: JSON type caster

Поиск
Список
Период
Сортировка
От Daniele Varrazzo
Тема Re: JSON type caster
Дата
Msg-id CA+mi_8Zz0q1_-+zW-GfY3CbcT_cikwc9+UAhxDkkSmrF7z3emQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: JSON type caster  (Tobias Oberstein <tobias.oberstein@gmail.com>)
Ответы Re: JSON type caster  (Tobias Oberstein <tobias.oberstein@gmail.com>)
Список psycopg
On Wed, Sep 19, 2012 at 2:42 PM, Tobias Oberstein
<tobias.oberstein@gmail.com> wrote:
>> Uhm... but what about a new function? To be called
>>
>>      psycopg2.extras.register_default_json(globally=True, loads=loads)
>>
>> or
>>      conn = psycopg2.connect(...)
>>      psycopg2.extras.register_default_json(conn, loads=loads)
>>
>
> +1 for that:
>
> it provides a simple to use interface for the use case "PG >=9.2 and global
> custom json"

Done (this function plus the conn_or_curs argument optional if not
required, instead of requiring an explicit None)



>>      class Json(object):
>>          def __init__(self, adapted, dumps=None):
>>              self.adapted = adapted
>>              self._dumps = dumps is None and json.dumps or dumps

> +1 for that also ..adding dump argument and dropping kwargs forwarding,
> because customizing via kwargs on a per Json-instance basis is probably the
> less likely case compared to "I want to use one custom loads/dumps
> everywhere".

Done this too.


> Mmh. There is still some asymmetry: loads is configured
> globally or per connection, dumps is configured "per argument instance"
> (Json instance) ..

Yes, this is a little bit harder to kill. Json is peculiar on not
having a specific class to deal with, so the use of the adapter is
more explicit than with other data type. Modulo this issue, adapters
are only global whereas typecasters can be per connection or per
cursor too. I think it could be possible and desirable to register
adapters on more ristrected scopes.

-- Daniele


В списке psycopg по дате отправления:

Предыдущее
От: Tobias Oberstein
Дата:
Сообщение: Re: JSON type caster
Следующее
От: "Jonathan S. Katz"
Дата:
Сообщение: Re: Range Type Support