Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use query.params() for selectable queries #139

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions databases/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ def _build_query(

return query.bindparams(**values) if values is not None else query
elif values:
if query.is_selectable:
return query.params(**values)
return query.values(**values)

return query
Expand Down
10 changes: 10 additions & 0 deletions tests/test_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ def run_sync(*args, **kwargs):

return run_sync

@pytest.mark.parametrize("database_url", DATABASE_URLS)
@async_adapter
async def test_selectable_queries_with_params(database_url):
async with Database(database_url) as database:
async with database.transaction(force_rollback=True):
param = sqlalchemy.bindparam('price')
query = sqlalchemy.select([prices]).where(prices.c.price < param)
rows = await database.fetch_all(query=query, values={'price': 10})
list(rows)


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
Expand Down