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

Test the FindQuery class and how it turns expressions into Redis commands #642

Merged
merged 13 commits into from
Aug 5, 2024
2 changes: 1 addition & 1 deletion aredis_om/model/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def jsonable_encoder(
sqlalchemy_safe=sqlalchemy_safe,
)
if dataclasses.is_dataclass(obj):
return dataclasses.asdict(obj)
return dataclasses.asdict(obj) # type: ignore[call-overload]
if isinstance(obj, Enum):
return obj.value
if isinstance(obj, PurePath):
Expand Down
11 changes: 10 additions & 1 deletion aredis_om/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,9 @@ def resolve_redisearch_query(cls, expression: ExpressionOrNegated) -> str:

return result

async def execute(self, exhaust_results=True, return_raw_result=False):
async def execute(
self, exhaust_results=True, return_raw_result=False, return_query_args=False
):
args: List[Union[str, bytes]] = [
"FT.SEARCH",
self.model.Meta.index_name,
Expand All @@ -898,6 +900,9 @@ async def execute(self, exhaust_results=True, return_raw_result=False):
if self.nocontent:
args.append("NOCONTENT")

if return_query_args:
return self.model.Meta.index_name, args

# Reset the cache if we're executing from offset 0.
if self.offset == 0:
self._model_cache.clear()
Expand Down Expand Up @@ -931,6 +936,10 @@ async def execute(self, exhaust_results=True, return_raw_result=False):
self._model_cache += _results
return self._model_cache

async def get_query(self):
query = self.copy()
return await query.execute(return_query_args=True)

async def first(self):
query = self.copy(offset=0, limit=1, sort_fields=self.sort_fields)
results = await query.execute(exhaust_results=False)
Expand Down
Loading
Loading