Re: Overriding default adapters in psycopg
| От | Adrian Klaver |
|---|---|
| Тема | Re: Overriding default adapters in psycopg |
| Дата | |
| Msg-id | f35c63af-037f-46c5-a99f-9bb514681cf7@aklaver.com обсуждение исходный текст |
| Ответ на | Overriding default adapters in psycopg (Christophe Pettus <xof@thebuild.com>) |
| Список | psycopg |
On 11/16/25 08:56, Christophe Pettus wrote:
> Hi!
>
> I am attempting to override the default adapters for JSON and JSONB in psycopg (3), but I am not quite sure how to go
aboutit (I'm testing using orjson for serialization and deserialization). This doesn't appear to work:
>
>> class CyanJSONBLoader(Loader):
>> def load(self, data):
>> return orjson.loads(data)
>>
>> psycopg.adapters.register_loader("jsonb", CyanJSONBLoader)
>>
>> class CyanJSONBDumper(Dumper):
>> def dump(self, obj):
>> return orjson.dumps(obj)
>>
>> psycopg.adapters.register_dumper("jsonb", CyanJSONBDumper)
>>
>
> The calls work, but the dump/load functions are never called.
I think you might need to use:
https://www.psycopg.org/psycopg3/docs/basic/adapt.html#adapt-json
>
> Thanks!
>
--
Adrian Klaver
adrian.klaver@aklaver.com
В списке psycopg по дате отправления: