revamp, returing will include the table name.cloumn_name. feat, ts_rank, ts_search helpers

This commit is contained in:
2025-11-02 22:04:02 +05:30
parent bb6a45732f
commit a795c0e8d6
9 changed files with 92 additions and 35 deletions

View File

@@ -18,6 +18,18 @@ func (f Field) Count() Field {
return Field("COUNT(" + f.String() + ")")
}
func ConcatWs(sep string, fields ...Field) Field {
return Field("concat_ws('" + sep + "'," + joinFileds(fields) + ")")
}
func StringAgg(exp, sep string) Field {
return Field("string_agg(" + exp + ",'" + sep + "')")
}
func StringAggCast(exp, sep string) Field {
return Field("string_agg(cast(" + exp + " as varchar),'" + sep + "')")
}
// StringEscape will wrap field with:
//
// COALESCE(field, ”)
@@ -141,6 +153,10 @@ func (f Field) DateTrunc(level, as string) Field {
return Field("DATE_TRUNC('" + level + "', " + f.String() + ") AS " + as)
}
func (f Field) TsRank(query, as string) Field {
return Field("TS_RANK(" + f.String() + ", " + query + ") AS " + as)
}
// EqualFold will use LOWER(column_name) = LOWER(val) for comparision
func (f Field) EqFold(val string) Conditioner {
col := f.String()
@@ -210,16 +226,9 @@ func (f Field) NotInSubQuery(qry WhereClause) Conditioner {
return &Cond{Field: col, Val: qry, op: " != ANY($)", action: CondActionSubQuery}
}
func ConcatWs(sep string, fields ...Field) Field {
return Field("concat_ws('" + sep + "'," + joinFileds(fields) + ")")
}
func StringAgg(exp, sep string) Field {
return Field("string_agg(" + exp + ",'" + sep + "')")
}
func StringAggCast(exp, sep string) Field {
return Field("string_agg(cast(" + exp + " as varchar),'" + sep + "')")
func (f Field) TsQuery(as string) Conditioner {
col := f.String()
return &Cond{Field: col, op: " @@ " + as, len: len(col) + 5}
}
func joinFileds(fields []Field) string {