fix: db helpers to be used with timestamps (#2627)
* fix: db helpers to be used with timestamps those helpers are used in boltz extension and they did not take dates into consideration yet * vlad picks * refactor get_placeholder --------- Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
+10
-4
@@ -65,6 +65,14 @@ def compat_timestamp_placeholder():
|
||||
return "?"
|
||||
|
||||
|
||||
def get_placeholder(model: Any, field: str) -> str:
|
||||
type_ = model.__fields__[field].type_
|
||||
if type_ == datetime.datetime:
|
||||
return compat_timestamp_placeholder()
|
||||
else:
|
||||
return "?"
|
||||
|
||||
|
||||
class Compat:
|
||||
type: Optional[str] = "<inherited>"
|
||||
schema: Optional[str] = "<inherited>"
|
||||
@@ -422,10 +430,8 @@ class Filter(BaseModel, Generic[TFilterModel]):
|
||||
|
||||
@property
|
||||
def statement(self):
|
||||
if self.model and self.model.__fields__[self.field].type_ == datetime.datetime:
|
||||
placeholder = compat_timestamp_placeholder()
|
||||
else:
|
||||
placeholder = "?"
|
||||
assert self.model, "Model is required for statement generation"
|
||||
placeholder = get_placeholder(self.model, self.field)
|
||||
if self.op in (Operator.INCLUDE, Operator.EXCLUDE):
|
||||
placeholders = ", ".join([placeholder] * len(self.values))
|
||||
stmt = [f"{self.field} {self.op.as_sql} ({placeholders})"]
|
||||
|
||||
Reference in New Issue
Block a user