derived table and row number addition
This commit is contained in:
22
pgm_table.go
22
pgm_table.go
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user