Skip to content

Commit

Permalink
fix(#338): Query repository list method for custom queries (#379)
Browse files Browse the repository at this point in the history
fix: query repository list method for custom queries
  • Loading branch information
vladpi authored Feb 16, 2025
1 parent 22df9d6 commit a0586df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions advanced_alchemy/repository/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from sqlalchemy import (
Delete,
Result,
Row,
RowMapping,
Select,
TextClause,
Expand Down Expand Up @@ -2184,7 +2185,7 @@ async def _list_and_count_basic(
instances.append(instance)
return instances, count

async def list(self, statement: Select[Any], **kwargs: Any) -> list[RowMapping]:
async def list(self, statement: Select[Any], **kwargs: Any) -> list[Row[Any]]:
"""Get a list of instances, optionally filtered.
Args:
Expand All @@ -2197,7 +2198,7 @@ async def list(self, statement: Select[Any], **kwargs: Any) -> list[RowMapping]:
with wrap_sqlalchemy_exception(error_messages=self.error_messages):
statement = self._filter_statement_by_kwargs(statement, **kwargs)
result = await self.execute(statement)
return list(result.scalars())
return list(result.all())

def _filter_statement_by_kwargs(
self,
Expand Down
5 changes: 3 additions & 2 deletions advanced_alchemy/repository/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from sqlalchemy import (
Delete,
Result,
Row,
RowMapping,
Select,
TextClause,
Expand Down Expand Up @@ -2181,7 +2182,7 @@ def _list_and_count_basic(
instances.append(instance)
return instances, count

def list(self, statement: Select[Any], **kwargs: Any) -> list[RowMapping]:
def list(self, statement: Select[Any], **kwargs: Any) -> list[Row[Any]]:
"""Get a list of instances, optionally filtered.
Args:
Expand All @@ -2194,7 +2195,7 @@ def list(self, statement: Select[Any], **kwargs: Any) -> list[RowMapping]:
with wrap_sqlalchemy_exception(error_messages=self.error_messages):
statement = self._filter_statement_by_kwargs(statement, **kwargs)
result = self.execute(statement)
return list(result.scalars())
return list(result.all())

def _filter_statement_by_kwargs(
self,
Expand Down

0 comments on commit a0586df

Please sign in to comment.