Gino: How to execute raw sql with parameters?

Created on 5 Mar 2019  路  3Comments  路  Source: python-gino/gino

Description

I'm trying to execute raw sql and pass it parameters. I'm attempting to follow the instructions set out here as a base: https://github.com/fantix/gino/issues/321
But I can't get anything to work.

What I Did

I've tried

    async with db.acquire() as conn:
       promo_audit = await conn.raw_connection.execute('select * from promotion_audit where id = :idName').execution_options(idName=1)
      print(promo_audit)

but get back

AttributeError: 'CoroWrapper' object has no attribute 'execution_options'

I tried:

promo_audit = await db.status('select * from promotion_audit where id = ?', 1)
promo_audit = await db.status('select * from promotion_audit where id = :idName', idName=1)
promo_audit = await db.status('select * from promotion_audit where id = :idName', { 'idName' : 1})
promo_audit = await db.status('select * from promotion_audit where id = :idName').execution_options(idName=1)

But get back variations of:

syntax error at or near ":" at character 42
STATEMENT:  select * from promotion_audit where id = :idName

Could someone please provide an example of how to do it? Thanks

question

Most helpful comment

For now, you need the db.text wrapper:

promo_audit = await db.status(db.text('select * from promotion_audit where id = :idName'), {'idName' : 1})

All 3 comments

For now, you need the db.text wrapper:

promo_audit = await db.status(db.text('select * from promotion_audit where id = :idName'), {'idName' : 1})

Thank you so much @fantix ! That works :)

Anytime 馃槂

Was this page helpful?
0 / 5 - 0 ratings

Related issues

saeedghx68 picture saeedghx68  路  6Comments

KoustavCode picture KoustavCode  路  3Comments

filantus picture filantus  路  3Comments

willyhakim picture willyhakim  路  4Comments

bnopne picture bnopne  路  5Comments