flexi adaption/casting scheme
От | Tobias Oberstein |
---|---|
Тема | flexi adaption/casting scheme |
Дата | |
Msg-id | 505B8FB6.6090906@gmail.com обсуждение исходный текст |
Ответы |
Re: flexi adaption/casting scheme
|
Список | psycopg |
Hi, I'd like to implement a certain type adaption/casting scheme and struggle with the right approach. Maybe someone can give me a hint? Would be great and welcome! Context: I am _only_ concerned with calling stored procedures, so there is the complete type metadata from PG catalog regarding the PG side available to use for mapping. PG => Py (typecasting): ----------------------- 1.1 hstore => plain Python dict 1.2 JSON => json.loads() .. whatever Python object that gives 1.3 composite type => plain Python dict with key/value pairs only for all attributes in the composite type that have non-NULL values 1.4 everything else => as per-default with Psycopg Py => PG (adaption): -------------------- 2.1 plain Python dict ..: 2.1.1 PG target type = hstore => dict-to-hstore with conversion of keys/values to str repr. if needed 2.1.2 PG target type = JSON => json.dumps() whatever str that produces 2.1.3 PG target type = composite type => for every key in the Python dict that is an attribute in the composite type, fill in the value from the dict; for every attribute in the composite type where there is no key in the Python dict, fill in NULL 2.2 everything else => as per-default with Psycopg == Above should work with nested PG types (array of composite type with an attribute again composite type etc etc). It should work with IN, OUT, INOUT parameters and array, setof, etc returning procedures. == How do I tackle this? Or even more fundamental: is it sane / doable at all (using public Psycopg hooks only)? Thanks alot, Tobias
В списке psycopg по дате отправления: