Documentation ¶
Overview ¶
Package sqlgen allows for SQL queries to be automatically generated.
Index ¶
- Constants
- func ReportInsert(log logging.LogSink, started time.Time, mainTable string, sql string, ...)
- func ReportSelect(log logging.LogSink, started time.Time, mainTable string, sql string, ...)
- func ReportUpdate(log logging.LogSink, started time.Time, mainTable string, sql string, ...)
- func SingleRow(rf func(RowDef)) func(FieldSet)
- type FieldDefFunc
- type FieldSet
- type Inserter
- type RowDef
Constants ¶
View Source
const DoNothing = `on conflict do nothing`
DoNothing is useful as the conflict argument of inserter.Exec
View Source
const Upsert = `on conflict {{.Candidates}} do update set {{.NonCandidates}} = {{.NSNonCandidates "excluded"}}`
Upsert is useful as the conflict argument of inserter.Exec
Variables ¶
This section is empty.
Functions ¶
func ReportInsert ¶
func ReportInsert(log logging.LogSink, started time.Time, mainTable string, sql string, rowcount int, err error, vals ...interface{})
ReportInsert traces SQL inserts
func ReportSelect ¶
func ReportSelect(log logging.LogSink, started time.Time, mainTable string, sql string, rowcount int, err error, vals ...interface{})
ReportSelect traces SQL selects
Types ¶
type FieldDefFunc ¶
type FieldDefFunc func(fmt, col string, vals ...interface{})
FieldDefFunc represents RowDef.FD and RowDef.CF.
type FieldSet ¶
type FieldSet interface { // It adds a row to the set. Row(func(RowDef)) // Potent returns true if this FieldSet would produce a useful SQL query. // If Potent() returns false, there's no purpose in using this FieldSet with the database. Potent() bool // InsertSQL generates and returns an INSERT query to send to the database to insert this FieldSet. // The conflict string is used to resolve duplicate rows in an upserty kind of a way. // It allows Go template formatting. InsertSQL(table string, conflict string) string // InsertValues produces a slice of values for INSERTs, such that the positions of values will match up // with SQL replacements in an InsertSQL call. InsertValues() []interface{} // RowCount returns the number of rows in the FieldSet. RowCount() int }
A FieldSet collects the requirements of a set of fields, and then helps generate SQL related to it.
type RowDef ¶
type RowDef interface { // FD is short for Field Definition - used for defining fields in the row. FD(fmt string, col string, vals ...interface{}) // CF is short for Candidate Field - used to define fields in the row that participate in distinguishing the row. // Two rows with the same values for their "CFs" will be considered the same. CF(fmt string, col string, vals ...interface{}) KV(col string, val interface{}) }
A RowDef serves to define individual rows within a FieldSet
Click to show internal directories.
Click to hide internal directories.