derived table and row number addition

This commit is contained in:
2025-10-21 00:27:00 +05:30
parent 12d6fface6
commit 9837fb1e37
6 changed files with 112 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"slices"
"strconv"
"strings"
@@ -103,6 +104,7 @@ type (
First
All
Stringer
Bulder
}
RowScanner interface {
@@ -128,6 +130,10 @@ type (
AllTx(ctx context.Context, tx pgx.Tx, rows RowsCb) error
}
Bulder interface {
Build(needArgs bool) (qry string, args []any)
}
selectQry struct {
table string
fields []Field
@@ -291,6 +297,17 @@ func (q *selectQry) raw(prefixArgs []any) (string, []any) {
}
func (q *selectQry) String() string {
qry, _ := q.Build(false)
if q.debug {
fmt.Println("***")
fmt.Println(qry)
fmt.Printf("%+v\n", q.args)
fmt.Println("***")
}
return qry
}
func (q *selectQry) Build(needArgs bool) (qry string, args []any) {
sb := getSB()
defer putSB(sb)
@@ -356,14 +373,19 @@ func (q *selectQry) String() string {
sb.WriteString(strconv.Itoa(q.offset))
}
qry := sb.String()
qry = sb.String()
if q.debug {
fmt.Println("***")
fmt.Println(qry)
fmt.Printf("%+v\n", q.args)
fmt.Println("***")
}
return qry
if needArgs {
args = slices.Clone(q.args)
}
return
}
func (q *selectQry) averageLen() int {