Documentation
¶
Overview ¶
Package sqlgen generates SQL for liteorm's core. It is built around a Dialect interface plus a Feature capability bitmask and clause-assembly logic, and always emits BOUND placeholders (never inlined literals). The four dialect renderers live in dialects.go; all four render correctly under sqlgen_test.go, and SQLite is the dialect wired to a live DB.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( SQLite dialect.Dialect = sqliteDialect{} Postgres dialect.Dialect = postgresDialect{} MySQL dialect.Dialect = mysqlDialect{} MSSQL dialect.Dialect = mssqlDialect{} )
The four render-only dialects. Each implements dialect.Dialect. SQLite is the dialect wired to a live DB; the other three exist so the builder's correctness is proven across placeholder/quote/limit/upsert/returning divergences in sqlgen_test.go.
Functions ¶
This section is empty.
Types ¶
type CTE ¶
CTE is one named common table expression in a WITH clause. Recursive marks the whole WITH as RECURSIVE (the keyword is emitted once if any CTE sets it).
type Column ¶
Column is a (optionally table-qualified) identifier in a SELECT list. Both parts are quoted via the dialect; Table is omitted when empty.
type CompoundTerm ¶
CompoundTerm is one arm of a compound select. Op is the set operator ("UNION", "INTERSECT", "EXCEPT"; empty means UNION); All keeps duplicates.
type Conflict ¶
type Conflict struct {
Columns []string
Update []string
// Nothing renders ON CONFLICT ... DO NOTHING (ignore the conflicting row)
// instead of DO UPDATE — the typed form of INSERT OR IGNORE. On MySQL it is a
// no-op ON DUPLICATE KEY UPDATE; on SQL Server, a MERGE with no WHEN MATCHED arm.
Nothing bool
}
Conflict is the upsert spec for an INSERT. Columns are the conflict-target columns; Update are the columns to overwrite on conflict.
type Expr ¶
Expr is a raw SQL fragment carrying positional "?" markers plus their args. The builder rewrites each "?" to the dialect's placeholder and appends args in order — this is how a single "?"-based fragment renders as $n (pg) or @pN (mssql).
type Insert ¶
type Insert struct {
Table string
Columns []string
Rows [][]any
OnConflict *Conflict
Returning []string
}
Insert is an INSERT statement model with optional multi-row VALUES, upsert, and RETURNING/OUTPUT. Identifiers are quoted; values bind as placeholders.
type Lock ¶
Lock models SELECT row locking. Strength is "UPDATE" or "SHARE"; at most one of SkipLocked / NoWait applies (NoWait wins if both are set).
type Select ¶
type Select struct {
With []CTE // WITH common table expressions, prepended to the statement
Table string // the FROM table (quoted); ignored when FromSubquery is set
FromSubquery *Select // a derived-table FROM source: FROM (sub) AS FromAlias
FromAlias string
Columns []Column
Projection []string // a raw select list (verbatim, no binds); overridden by ProjectionExprs
// ProjectionExprs is a select list whose items may carry "?" binds (e.g. a
// scalar subquery in SELECT). It renders before FROM so its binds number first;
// it takes precedence over Projection and Columns.
ProjectionExprs []Expr
Distinct bool
DistinctOn []string // SELECT DISTINCT ON (cols) — Postgres; overrides Distinct
Joins []Expr
Where []Expr
GroupBy []string
Having []Expr
OrderBy []string
Limit int
Offset int
HasLimit bool
HasOffset bool
Union []CompoundTerm
Lock *Lock // row-level locking (FOR UPDATE/SHARE), applied to the whole statement
}
Select is a SELECT statement model. Identifiers in Columns and Table are quoted; Joins/Where/OrderBy/GroupBy are raw SQL fragments (Joins/Where/Having may carry "?"). When Projection is non-empty it is the raw select list (used for count(*) and projections), overriding Columns. Union holds compound arms; the outer Select's ORDER BY/LIMIT apply to the whole compound.
func (Select) Build ¶
Build renders s for the dialect, returning the SQL and ordered args. When s has Union arms it renders `core UNION [ALL] core …` and applies the outer ORDER BY/LIMIT to the whole compound. Placeholder numbering (n) is global across the join, where, having, and every union arm — so a single "?"-based model renders as $1,$2,… in order on Postgres.
type SetClause ¶
SetClause is one column assignment in an UPDATE. SetClause assigns a column. By default it binds Arg as a placeholder (col = ?); when SQL is non-empty it is a raw assignment expression (col = SQL, which may carry "?" markers bound by Args) — used for correlated UPDATE … FROM where the value comes from the FROM source.