Slide 30
Slide 30 text
In our case we don't have to write much
async def insert_ticker(tick: NamedTuple, *, pool: Pool, table: str) -> None:
fields = tick._fields
# this is definitely uglier than psycopg2
placeholders = ['${}'.format(i) for i, _ in enumerate(fields, 1)]
query = 'INSERT INTO {} ({}) VALUES ({})'.format(
table, ', '.join(fields), ', '.join(placeholders))
async with pool.acquire() as connection: # yes, this is a thing!
async with connection.transaction():
await connection.execute(query, *tick)