How would you implement Date Time based filters #49
-
The way to built queries is very interesting. I wonder how you would approach this if you had a DateTime based filter like:
And somehow you had to build a query with Line 144 in aab552f |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Good question. I usually separate out the two filters. So if it's a filtered on a type WidgetFilter struct {
CreatedAfter *time.Time
CreatedBefore *time.Time
} Then in the SQL construction it would look something like: if v := filter.CreatedAfter; v != nil {
where = append(where, "created_at >= ?")
args = append(args, *v)
}
if v := filter.CreatedBefore; v != nil {
where = append(where, "created_at < ?")
args = append(args, *v)
} |
Beta Was this translation helpful? Give feedback.
Good question. I usually separate out the two filters. So if it's a filtered on a
Created
timestamp then I would haveCreatedAfter
andCreatedBefore
fields on my filter:Then in the SQL construction it would look something like: