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

@@ -2,10 +2,11 @@ package pgm
// Table in database
type Table struct {
Name string
PK []string
FieldCount uint16
debug bool
Name string
DerivedTable Query
PK []string
FieldCount uint16
debug bool
}
// Debug when set true will print generated query string in stdout
@@ -14,6 +15,10 @@ func (t *Table) Debug() Clause {
return t
}
func (t *Table) Field(f string) Field {
return Field(t.Name + "." + f)
}
// Insert table statement
func (t *Table) Insert() InsertClause {
qb := &insertQry{
@@ -30,10 +35,17 @@ func (t *Table) Insert() InsertClause {
func (t *Table) Select(field ...Field) SelectClause {
qb := &selectQry{
debug: t.debug,
table: t.Name,
fields: field,
}
if t.DerivedTable != nil {
tName, args := t.DerivedTable.Build(true)
qb.table = "(" + tName + ") AS " + t.Name
qb.args = args
} else {
qb.table = t.Name
}
return qb
}