Adding In filter to back

This commit is contained in:
2023-03-11 22:48:27 +01:00
parent 598a962aba
commit f2ddc4303e

View File

@@ -1,4 +1,5 @@
from beanie import PydanticObjectId
from beanie.odm.operators.find.comparison import In
from beanie.operators import And, RegEx, Eq
from fastapi import APIRouter, HTTPException, Depends
@@ -43,11 +44,13 @@ def parse_query(query: str, model):
elif operator == 'eq':
operand = Eq(column, value)
elif operator == 'in':
operand = In(column, value.split(','))
and_array.append(operand)
if and_array:
return And(and_array) if len(and_array) > 1 else and_array[0]
return And(*and_array) if len(and_array) > 1 else and_array[0]
else:
return {}