Re: JSON type caster - Mailing list psycopg

From Daniele Varrazzo
Subject Re: JSON type caster
Date
Msg-id CA+mi_8bT4CgQPgXg+6=1Q=65-gMAWZWHZ4Jy+uLCwfb6y2LrBA@mail.gmail.com
Whole thread Raw
In response to Re: JSON type caster  (Tobias Oberstein <tobias.oberstein@gmail.com>)
List psycopg
On Tue, Sep 18, 2012 at 9:12 PM, Tobias Oberstein
<tobias.oberstein@gmail.com> wrote:

> If there is no other "default mapping" of Python dicts to any other
> PG type, that would make a nice fallback that probably allows to handle
> a lot of situations automatically - such as stored procs that expect
> their JSON args to be dicts anyway.

I think it can be easily done: currently there's no default adaptation
for dicts: there is the hstore adapter but it must be registered
manually.

If we have the Json wrapper, I suspect adapting dicts would be just a matter of:

    register_adapter(dict, Json)

it would work with lists and other objects as well, but overriding the
default adapter (e.g. lists to arrays etc.). Because adapters are
currently global this may result in unwanted side effects.

It is definitely an use case to be mentioned in the docs.

Cheers,

-- Daniele


psycopg by date:

Previous
From: Tobias Oberstein
Date:
Subject: Re: JSON type caster
Next
From: Daniele Varrazzo
Date:
Subject: Re: JSON type caster