Field, date truncate method

This commit is contained in:
2025-10-21 16:45:43 +05:30
parent 9837fb1e37
commit 2551e07b3e

View File

@@ -131,6 +131,16 @@ func (f Field) IsNotNull() Conditioner {
return &Cond{Field: col, op: " IS NOT NULL", len: len(col) + 12} return &Cond{Field: col, op: " IS NOT NULL", len: len(col) + 12}
} }
// DateTrunc will truncate date or timestamp to specified level of precision
//
// Level values:
// - microseconds, milliseconds, second, minute, hour
// - day, week (Monday start), month, quarter, year
// - decade, century, millennium
func (f Field) DateTrunc(level, as string) Field {
return Field("DATE_TRUNC('" + level + "', " + f.String() + ") AS " + as)
}
// EqualFold will use LOWER(column_name) = LOWER(val) for comparision // EqualFold will use LOWER(column_name) = LOWER(val) for comparision
func (f Field) EqFold(val string) Conditioner { func (f Field) EqFold(val string) Conditioner {
col := f.String() col := f.String()