revamp, returing will include the table name.cloumn_name. feat, ts_rank, ts_search helpers
This commit is contained in:
25
pgm_table.go
25
pgm_table.go
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user