60 lines
1.0 KiB
Go
60 lines
1.0 KiB
Go
package pgm
|
|
|
|
// Table in database
|
|
type Table struct {
|
|
Name string
|
|
PK []string
|
|
FieldCount uint16
|
|
debug bool
|
|
}
|
|
|
|
// Debug when set true will print generated query string in stdout
|
|
func (t *Table) Debug() Clause {
|
|
t.debug = true
|
|
return t
|
|
}
|
|
|
|
// Insert table statement
|
|
func (t *Table) Insert() InsertClause {
|
|
qb := &insertQry{
|
|
debug: t.debug,
|
|
table: t.Name,
|
|
fields: make([]string, 0, t.FieldCount),
|
|
vals: make([]string, 0, t.FieldCount),
|
|
args: make([]any, 0, t.FieldCount),
|
|
}
|
|
return qb
|
|
}
|
|
|
|
// Select table statement
|
|
func (t *Table) Select(field ...Field) SelectClause {
|
|
qb := &selectQry{
|
|
debug: t.debug,
|
|
table: t.Name,
|
|
fields: field,
|
|
}
|
|
|
|
return qb
|
|
}
|
|
|
|
// Update table statement
|
|
func (t *Table) Update() UpdateClause {
|
|
qb := &updateQry{
|
|
debug: t.debug,
|
|
table: t.Name,
|
|
cols: make([]string, 0, t.FieldCount),
|
|
args: make([]any, 0, t.FieldCount),
|
|
}
|
|
return qb
|
|
}
|
|
|
|
// Detlete table statement
|
|
func (t *Table) Delete() DeleteCluase {
|
|
qb := &deleteQry{
|
|
debug: t.debug,
|
|
table: t.Name,
|
|
}
|
|
|
|
return qb
|
|
}
|