fix db filtering
This commit is contained in:
@@ -237,7 +237,7 @@ class BotEntity[CreateSchemaType: BaseModel, UpdateSchemaType: BaseModel](
|
|||||||
cls, select_statement: SelectOfScalar[Self], static_filter: list[Filter]
|
cls, select_statement: SelectOfScalar[Self], static_filter: list[Filter]
|
||||||
):
|
):
|
||||||
for sfilt in static_filter:
|
for sfilt in static_filter:
|
||||||
column = col(getattr(cls, sfilt.field_name))
|
column = getattr(cls, sfilt.field_name)
|
||||||
if sfilt.operator == "==":
|
if sfilt.operator == "==":
|
||||||
condition = column.__eq__(sfilt.value)
|
condition = column.__eq__(sfilt.value)
|
||||||
elif sfilt.operator == "!=":
|
elif sfilt.operator == "!=":
|
||||||
@@ -251,19 +251,19 @@ class BotEntity[CreateSchemaType: BaseModel, UpdateSchemaType: BaseModel](
|
|||||||
elif sfilt.operator == ">=":
|
elif sfilt.operator == ">=":
|
||||||
condition = column.__ge__(sfilt.value)
|
condition = column.__ge__(sfilt.value)
|
||||||
elif sfilt.operator == "ilike":
|
elif sfilt.operator == "ilike":
|
||||||
condition = column.ilike(f"%{sfilt.value}%")
|
condition = col(column).ilike(f"%{sfilt.value}%")
|
||||||
elif sfilt.operator == "like":
|
elif sfilt.operator == "like":
|
||||||
condition = column.like(f"%{sfilt.value}%")
|
condition = col(column).like(f"%{sfilt.value}%")
|
||||||
elif sfilt.operator == "in":
|
elif sfilt.operator == "in":
|
||||||
condition = column.in_(sfilt.value)
|
condition = col(column).in_(sfilt.value)
|
||||||
elif sfilt.operator == "not in":
|
elif sfilt.operator == "not in":
|
||||||
condition = column.notin_(sfilt.value)
|
condition = col(column).notin_(sfilt.value)
|
||||||
elif sfilt.operator == "is none":
|
elif sfilt.operator == "is none":
|
||||||
condition = column.is_(None)
|
condition = col(column).is_(None)
|
||||||
elif sfilt.operator == "is not none":
|
elif sfilt.operator == "is not none":
|
||||||
condition = column.isnot(None)
|
condition = col(column).isnot(None)
|
||||||
elif sfilt.operator == "contains":
|
elif sfilt.operator == "contains":
|
||||||
condition = sfilt.value == column.any_()
|
condition = sfilt.value == col(column).any_()
|
||||||
else:
|
else:
|
||||||
condition = None
|
condition = None
|
||||||
if condition is not None:
|
if condition is not None:
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ class EnumType(TypeDecorator):
|
|||||||
def process_bind_param(self, value, dialect):
|
def process_bind_param(self, value, dialect):
|
||||||
if value and isinstance(value, EnumMember):
|
if value and isinstance(value, EnumMember):
|
||||||
return value.value
|
return value.value
|
||||||
return None
|
return str(value)
|
||||||
|
|
||||||
def process_result_value(self, value, dialect):
|
def process_result_value(self, value, dialect):
|
||||||
if value:
|
if value:
|
||||||
|
|||||||
Reference in New Issue
Block a user