Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,11 @@ async def chunk_by_id_desc(self, count: int, column: str = None, alias: str = No
yield results

def new(self):
return self.connection.query()
# Carry the current table so a nested builder (e.g. a where(lambda ...)
# subgroup) prefixes its columns correctly instead of rendering a
# table-less ."column". Callers that want a different table override it
# with .table(...) as usual.
return self.connection.query().table(self._table)

def invalid_operator(self, operator):
"""Determine whether an operator is not supported by the builder."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,30 @@ async def test_delete_with_multiple_wheres(self):
sql, bindings = mock_delete.call_args[0]
self.assertEqual(sql, 'DELETE FROM "users" WHERE "age" = ? AND "profile" = ?')
self.assertEqual(list(bindings), [20, 1])

async def test_where_grouped_lambda_prefixes_subgroup_columns(self):
sql = (
User.query()
.where("name", "Joe")
.where(lambda q: q.where("active", 1).where("age", ">", 20).or_where("id", ">=", 42))
.to_sql()
)
self.assertEqual(
sql,
'SELECT * FROM "users" WHERE "users"."name" = \'Joe\' AND '
'("users"."active" = \'1\' AND "users"."age" > \'20\' OR "users"."id" >= \'42\')',
)

async def test_where_grouped_lambda_to_qmark_binding_order(self):
builder = (
User.query()
.where("name", "Joe")
.where(lambda q: q.where("active", 1).where("age", ">", 20).or_where("id", ">=", 42))
)
sql = builder.to_qmark()
self.assertEqual(
sql,
'SELECT * FROM "users" WHERE "users"."name" = ? AND '
'("users"."active" = ? AND "users"."age" > ? OR "users"."id" >= ?)',
)
self.assertEqual(list(builder._bindings), ["Joe", 1, 20, 42])
2 changes: 1 addition & 1 deletion fastapi_startkit/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading