Skip to content

Commit

Permalink
Fix 'execute' so that it can work with sqlalchemy params
Browse files Browse the repository at this point in the history
  • Loading branch information
nhumrich committed Aug 10, 2017
1 parent 302b3c5 commit 0ed9b09
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion asyncpgsa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from .pgsingleton import PG
from .connection import compile_query

__version__ = '0.14.1'
__version__ = '0.14.2'
pg = PG()

5 changes: 3 additions & 2 deletions asyncpgsa/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ class SAConnection(connection.Connection):

def _execute(self, query, args, limit, timeout, return_status=False):
query, compiled_args = compile_query(query, dialect=self._dialect)
args = tuple(compiled_args) + args
args = compiled_args or args
return super()._execute(query, args, limit, timeout,
return_status=return_status)

async def execute(self, script, *args, **kwargs) -> str:
# script, params = compile_query(script, dialect=self._dialect)
script, params = compile_query(script, dialect=self._dialect)
args = params or args
result = await super().execute(script, *args, **kwargs)
return RecordGenerator(result)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_pgsingleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ async def test_sql_with_arguments():
assert bool(result)


async def test_execute_with_sa_arguments():
script = sa.select('*').select_from(sa.text('sqrt(:num) as a'))
script = script.params(num=16)
result = await pg.execute(script)
assert bool(result)

async def test_transaction():
async with pg.transaction() as conn:
for row in await conn.fetch(query):
Expand Down

0 comments on commit 0ed9b09

Please sign in to comment.