Asyncpg: convert Record object to json

Created on 15 Feb 2018  路  1Comment  路  Source: MagicStack/asyncpg

hi, i have a table like this:

    Id
    Name
    Price

And i get a product with this:

async with db.acquire() as connection:
    product = await connection.fetchrow('''
        SELECT id, name, price FROM product WHERE id = 1
    ''')

i want the below result:

{
    'id': 1,
    'name': 'asyncpg',
    'price': 3
}

i want to get a json result from query, and Question is: How do it?

Most helpful comment

Cast it to a dict: product = dict(connection.fetchrow(...

>All comments

Cast it to a dict: product = dict(connection.fetchrow(...

Was this page helpful?
0 / 5 - 0 ratings