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

@@ -1,7 +1,14 @@
package pgm
import (
"strconv"
)
// Table in database
type Table struct {
tsQuery *string
tsQueryAs *string
Name string
DerivedTable Query
PK []string
@@ -31,6 +38,12 @@ func (t *Table) Insert() InsertClause {
return qb
}
func (t *Table) WithTsQuery(q, as string) *Table {
t.tsQuery = &q
t.tsQueryAs = &as
return t
}
// Select table statement
func (t *Table) Select(field ...Field) SelectClause {
qb := &selectQry{
@@ -46,6 +59,18 @@ func (t *Table) Select(field ...Field) SelectClause {
qb.table = t.Name
}
if t.tsQuery != nil {
var as string
if t.tsQueryAs != nil && *t.tsQueryAs != "" {
as = *t.tsQueryAs
} else {
// add default as field
as = "query"
}
qb.args = append(qb.args, as)
qb.table += ", TO_TSQUERY('english', $" + strconv.Itoa(len(qb.args)) + ") " + as
}
return qb
}