Asyncpg: Add ability to set the Record factory on the connection

Created on 31 Oct 2016  路  3Comments  路  Source: MagicStack/asyncpg

In order to provide for alternative ways of accessing fields, or adding custom functionality, make it possible to specify a Record factory on a connection.

See #38 and #13 for related discussions.

enhancement

Most helpful comment

The ability to use customized Record is a must, dude. It's been more than 2 years

Dear "dude", you're welcome to make a PR. Please make sure that the performance of asyncpg code that uses the builtin asyncpg.Record won't be impacted by it.

All 3 comments

@elprans nice. Incorporating this issue is invaluable.

This is necessary not only for dot accessor wanted in #38 and #13. I don't know any way to elegantly convert json, uuid objects from postgres to python objects except thru monkey patching.

What I am doing now is ugly IMO.

[
    {
        **record,
        'task_id': str(record['task_id']),  # uuid to str
        'rates': json.loads(t['rates']),  # jsonb to dict
    }
    for record in fetched_records
]

The ability to use customized Record is a must, dude. It's been more than 2 years

The ability to use customized Record is a must, dude. It's been more than 2 years

Dear "dude", you're welcome to make a PR. Please make sure that the performance of asyncpg code that uses the builtin asyncpg.Record won't be impacted by it.

Was this page helpful?
0 / 5 - 0 ratings