Documentation
¶
Overview ¶
Package jooq provides a type-safe, fluent SQL query builder for Go inspired by the Java library jOOQ. It combines parametric Field[T] columns, positional RecordN row types, step interfaces that make the clause order a compile-time concern, and runtime dialect translation from a single abstract syntax tree.
The package has no external dependencies. Queries are built as a detached abstract syntax tree and rendered to dialect-specific SQL at execution time, so the same query can target PostgreSQL or SQLite.
Index ¶
- Variables
- func BatchExec(ctx context.Context, db Querier, steps ...) ([]sql.Result, error)
- func FetchGroups[K comparable, S any](ctx context.Context, db Querier, q statement, keyColumn string) (map[K][]S, error)
- func FetchInto[S any](ctx context.Context, db Querier, q statement) ([]S, error)
- func FetchMap[K comparable, S any](ctx context.Context, db Querier, q statement, keyColumn string) (map[K]S, error)
- func FetchOneInto[S any](ctx context.Context, db Querier, q statement) (S, error)
- func ReturningInto[S any](ctx context.Context, db Querier, step statement) ([]S, error)
- func ReturningOneInto[S any](ctx context.Context, db Querier, step statement) (S, error)
- func WithTx(ctx context.Context, db *sql.DB, fn func(tx *sql.Tx) error) (err error)
- type AnyField
- type Assignment
- type CaseBuilder
- type Condition
- type DeleteConditionStep
- type DeleteFinalStep
- type DeleteReturningStep
- type DeleteWhereStep
- type Dialect
- type Field
- func Abs[T any](f Field[T]) Field[T]
- func Avg[T any](f Field[T]) Field[float64]
- func Cast[T any](f AnyField, sqlType string) Field[T]
- func Coalesce[T any](first Field[T], rest ...any) Field[T]
- func Concat(parts ...any) Field[string]
- func Count(f AnyField) Field[int64]
- func CountDistinct(f AnyField) Field[int64]
- func CountStar() Field[int64]
- func Function[T any](name string, args ...AnyField) Field[T]
- func Greatest[T any](first Field[T], rest ...any) Field[T]
- func Least[T any](first Field[T], rest ...any) Field[T]
- func Length(f Field[string]) Field[int64]
- func Lower(f Field[string]) Field[string]
- func Max[T any](f Field[T]) Field[T]
- func Min[T any](f Field[T]) Field[T]
- func NewField[T any](base TableImpl, name string) Field[T]
- func NullIf[T any](a Field[T], b T) Field[T]
- func Raw[T any](sql string) Field[T]
- func RawValue[T any](sql string, args ...any) Field[T]
- func Round[T any](f Field[T]) Field[T]
- func ScalarSubquery[T any](sub Subquery) Field[T]
- func Sum[T any](f Field[T]) Field[T]
- func Trim(f Field[string]) Field[string]
- func Upper(f Field[string]) Field[string]
- type ForeignKeyMeta
- type InsertConflictActionStep
- type InsertFinalStep
- type InsertOnConflictStep
- type InsertReturningStep
- type InsertSetMoreStep
- type InsertSetStep
- type InsertValuesStep
- type NumericField
- type OrderField
- type OverBuilder
- type Querier
- type Record1
- type Record2
- type Record3
- type Record4
- type Record5
- type Record6
- type Record7
- type Record8
- type Record9
- type Record10
- type Record11
- type Record12
- type Record13
- type Record14
- type Record15
- type Record16
- type Record17
- type Record18
- type Record19
- type Record20
- type Record21
- type Record22
- type SelectConditionStep
- type SelectFinalStep
- type SelectFromStep
- func Select1[T1 any](f1 Field[T1]) SelectFromStep[Record1[T1]]
- func Select2[T1, T2 any](f1 Field[T1], f2 Field[T2]) SelectFromStep[Record2[T1, T2]]
- func Select3[T1, T2, T3 any](f1 Field[T1], f2 Field[T2], f3 Field[T3]) SelectFromStep[Record3[T1, T2, T3]]
- func Select4[T1, T2, T3, T4 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4]) SelectFromStep[Record4[T1, T2, T3, T4]]
- func Select5[T1, T2, T3, T4, T5 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5]) SelectFromStep[Record5[T1, T2, T3, T4, T5]]
- func Select6[T1, T2, T3, T4, T5, T6 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) SelectFromStep[Record6[T1, T2, T3, T4, T5, T6]]
- func Select7[T1, T2, T3, T4, T5, T6, T7 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) SelectFromStep[Record7[T1, T2, T3, T4, T5, T6, T7]]
- func Select8[T1, T2, T3, T4, T5, T6, T7, T8 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) SelectFromStep[Record8[T1, T2, T3, T4, T5, T6, T7, T8]]
- func Select9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) SelectFromStep[Record9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]
- func Select10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) SelectFromStep[Record10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]
- func Select11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) SelectFromStep[Record11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]]
- func Select12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) SelectFromStep[Record12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]]
- func Select13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) ...
- func Select14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) ...
- func Select15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) ...
- func Select16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) ...
- func Select17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) ...
- func Select18[...](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) ...
- func Select19[...](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) ...
- func Select20[...](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) ...
- func Select21[...](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) ...
- func Select22[...](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], ...) ...
- type SelectGroupByStep
- type SelectHavingStep
- type SelectJoinStep
- type SelectLimitStep
- type SelectLockStep
- type SelectOnStep
- type SelectOrderByStep
- type SelectWhereStep
- type StringField
- type Subquery
- type Table
- type TableImpl
- type UniqueKeyMeta
- type UpdateConditionStep
- type UpdateFinalStep
- type UpdateReturningStep
- type UpdateSetMoreStep
- type UpdateSetStep
- type UpdateWhereStep
- type WindowField
- func AvgOver[T any](f Field[T]) WindowField[float64]
- func CountOver(f AnyField) WindowField[int64]
- func DenseRank() WindowField[int64]
- func FirstValue[T any](f Field[T]) WindowField[T]
- func Lag[T any](f Field[T]) WindowField[T]
- func LastValue[T any](f Field[T]) WindowField[T]
- func Lead[T any](f Field[T]) WindowField[T]
- func Rank() WindowField[int64]
- func RowNumber() WindowField[int64]
- func SumOver[T any](f Field[T]) WindowField[T]
Constants ¶
This section is empty.
Variables ¶
var ErrColumnValueMismatch = errors.New("jooq: column count does not match value count")
ErrColumnValueMismatch is recorded when an inserted row has a different number of values than there are columns.
var ErrEmptyInsert = errors.New("jooq: INSERT has no columns or values")
ErrEmptyInsert is recorded when an INSERT statement has neither columns nor a DEFAULT VALUES marker.
var ErrReturningUnsupported = errors.New("jooq: RETURNING is not supported by this dialect")
ErrReturningUnsupported is recorded when a RETURNING clause is requested for a dialect that does not support it. Both supported dialects (PostgreSQL and SQLite) render RETURNING natively, so this sentinel exists as a defensive guard for any dialect whose supportsReturning reports false.
var ErrTooManyRows = errors.New("jooq: query returned more than one row")
ErrTooManyRows is returned by FetchOne and FetchSingle when a query yields more rows than the caller expected.
var ErrUsingUnsupported = errors.New("gooq: DELETE ... USING is not supported by this dialect")
ErrUsingUnsupported is recorded when a DELETE ... USING clause is rendered for a dialect that does not support it. Only PostgreSQL supports DELETE ... USING; SQLite does not.
Functions ¶
func BatchExec ¶
func BatchExec(ctx context.Context, db Querier, steps ...interface { SQL() (string, []any, error) }) ([]sql.Result, error)
BatchExec renders and executes each statement in order against the given Querier, returning the result of every executed statement. Each step is any value exposing an SQL method, which every terminal INSERT, UPDATE, and DELETE builder satisfies. Execution stops at the first error: the slice returned alongside a non-nil error holds the results of the steps that ran before the failure. Rendering and execution share no transaction; wrap the call in one by passing a *sql.Tx as the Querier.
func FetchGroups ¶
func FetchGroups[K comparable, S any](ctx context.Context, db Querier, q statement, keyColumn string) (map[K][]S, error)
FetchGroups runs the statement, maps each row into a value of S, and groups the results by the value of keyColumn cast to K. The keyColumn must name one of the columns selected by the statement. Rows that share a key are appended to the same slice in result order.
func FetchInto ¶
FetchInto runs the supplied statement and maps every result row into a new value of the struct type S, returning the resulting slice.
Columns are matched to struct fields by the `db` struct tag; a field tagged `db:"col"` receives the value of the result column named "col". When a field has no db tag, its Go field name is matched case-insensitively against the column name. Result columns without a matching exported struct field are skipped. Pointer fields and types implementing the standard library sql.Scanner interface are supported, as are values implementing driver.Valuer. The error returned by rows.Err is propagated.
func FetchMap ¶
func FetchMap[K comparable, S any](ctx context.Context, db Querier, q statement, keyColumn string) (map[K]S, error)
FetchMap runs the statement, maps each row into a value of S, and indexes the results by the value of keyColumn cast to K. The keyColumn must name one of the columns selected by the statement. When two rows share a key, the later row overwrites the earlier one.
func FetchOneInto ¶
FetchOneInto runs the statement and returns a single mapped row. It returns the zero value of S and a nil error when no row matches, the single row when exactly one matches, or ErrTooManyRows when more than one row matches.
func ReturningInto ¶
ReturningInto executes a data-manipulation statement that renders a RETURNING clause and maps the returned rows into a slice of the struct type S.
Methods cannot introduce their own type parameters, so the typed RETURNING surface is exposed as a free generic function. The INSERT, UPDATE, and DELETE builders already render a RETURNING projection when Returning was called and already expose a SQL method, so the statement is run through QueryContext and its rows are mapped with the same plan FetchInto uses.
func ReturningOneInto ¶
ReturningOneInto executes a RETURNING statement and returns a single mapped row. It returns the zero value of S and a nil error when no row is returned, the single row when exactly one is returned, or ErrTooManyRows when more than one row is returned.
func WithTx ¶
WithTx runs fn inside a database transaction. The transaction is started with BeginTx and is committed when fn returns a nil error. When fn returns an error the transaction is rolled back and the returned error joins fn's error with any rollback error. When fn panics the transaction is rolled back and the panic is re-raised after the rollback completes.
The *sql.Tx passed to fn satisfies Querier, so every statement builder can be executed against it and participates in the same transaction.
Types ¶
type AnyField ¶
type AnyField interface {
// Name returns the unqualified column or expression name.
Name() string
// contains filtered or unexported methods
}
AnyField is a type-erased field usable where the element type does not matter: projection column lists, GROUP BY, INSERT column lists, and RETURNING.
type Assignment ¶
type Assignment interface {
// contains filtered or unexported methods
}
Assignment is a "column = value" pair used by UPDATE ... SET, by INSERT upsert update actions, and by INSERT ... SET. It is produced by Field[T].Set.
func SetToExcluded ¶
func SetToExcluded(f AnyField) Assignment
SetToExcluded builds an upsert assignment that sets a column to the value the conflicting INSERT attempted to write (EXCLUDED.col in PostgreSQL and excluded.col in SQLite). It is used inside DoUpdateSet.
type CaseBuilder ¶
type CaseBuilder[T any] struct { // contains filtered or unexported fields }
CaseBuilder accumulates the branches of a searched CASE expression. It is returned by Case and finalised with End, which yields a typed Field[T].
func Case ¶
func Case[T any]() CaseBuilder[T]
Case begins a searched CASE expression producing values of type T.
func (CaseBuilder[T]) Else ¶
func (c CaseBuilder[T]) Else(v T) CaseBuilder[T]
Else sets the ELSE result of the CASE expression, binding its value as an argument. Calling Else more than once replaces the previous ELSE value.
func (CaseBuilder[T]) End ¶
func (c CaseBuilder[T]) End() Field[T]
End finalises the CASE expression and returns it as a typed Field[T].
func (CaseBuilder[T]) When ¶
func (c CaseBuilder[T]) When(cond Condition, then T) CaseBuilder[T]
When adds a "WHEN condition THEN value" branch whose result value binds as an argument.
func (CaseBuilder[T]) WhenField ¶
func (c CaseBuilder[T]) WhenField(cond Condition, then Field[T]) CaseBuilder[T]
WhenField adds a "WHEN condition THEN field" branch whose result renders as the given field's column or expression rather than binding a value.
type Condition ¶
type Condition interface {
Field[bool]
And(other Condition) Condition
Or(other Condition) Condition
Not() Condition
}
Condition is a boolean predicate. Mirroring jOOQ, a Condition is itself a Field[bool], so it can be projected, compared, and stored in a variable, in addition to being combined with And, Or, and Not.
func And ¶
And combines the given conditions into a single conjunction rendered as one flat, parenthesized "(a AND b AND c)" group rather than nested pairs. With a single condition it returns that condition unchanged; with no conditions it returns True.
func Exists ¶
Exists returns a Condition rendering "EXISTS (SELECT ...)" over the given subquery. The subquery renders into the same builder as the surrounding statement, so its bind arguments are numbered in render order.
func False ¶
func False() Condition
False returns a condition that never holds, rendered as the constant predicate "1 = 0".
func NotExists ¶
NotExists returns a Condition rendering "NOT EXISTS (SELECT ...)" over the given subquery.
func Or ¶
Or combines the given conditions into a single disjunction rendered as one flat, parenthesized "(a OR b OR c)" group rather than nested pairs. With a single condition it returns that condition unchanged; with no conditions it returns False.
func RawCondition ¶
RawCondition is an escape hatch that splices verbatim SQL into the query as a boolean predicate, binding no arguments.
type DeleteConditionStep ¶
type DeleteConditionStep interface {
DeleteReturningStep
And(c Condition) DeleteConditionStep
Or(c Condition) DeleteConditionStep
}
DeleteConditionStep allows extending the WHERE predicate.
type DeleteFinalStep ¶
type DeleteFinalStep interface {
SQL() (string, []any, error)
SQLFor(d Dialect) (string, []any, error)
Using(d Dialect) DeleteFinalStep
Execute(ctx context.Context, db Querier) (sql.Result, error)
// contains filtered or unexported methods
}
DeleteFinalStep is the terminal state.
type DeleteReturningStep ¶
type DeleteReturningStep interface {
DeleteFinalStep
Returning(cols ...AnyField) DeleteFinalStep
}
DeleteReturningStep allows a RETURNING clause before terminal execution.
type DeleteWhereStep ¶
type DeleteWhereStep interface {
DeleteReturningStep
Where(c Condition) DeleteConditionStep
// UsingTable joins a further table into the DELETE through a USING clause,
// rendered before WHERE. Only PostgreSQL supports DELETE ... USING; the
// SQLite dialect records ErrUsingUnsupported. This clause is named
// UsingTable rather than Using because Using is reserved on the terminal
// step for selecting the rendering dialect.
UsingTable(t Table) DeleteWhereStep
}
DeleteWhereStep is the entry state after DELETE FROM table.
func DeleteFrom ¶
func DeleteFrom(t Table) DeleteWhereStep
DeleteFrom begins a DELETE from the given table.
type Dialect ¶
type Dialect interface {
// Name returns the canonical dialect identifier.
Name() string
// contains filtered or unexported methods
}
Dialect supplies every database-specific SQL fragment that the otherwise dialect-agnostic abstract syntax tree requires while rendering itself. A single tree is rendered against a chosen Dialect at SQL time, which is how one query can target multiple databases.
The interface is sealed: its operative methods are unexported, so callers obtain dialects only through Postgres and SQLite.
type Field ¶
type Field[T any] interface { Name() string // Comparisons against a value of the field's type. EQ(v T) Condition NE(v T) Condition GT(v T) Condition LT(v T) Condition GE(v T) Condition LE(v T) Condition // Set membership, nullability, and range. In(vs ...T) Condition NotIn(vs ...T) Condition // InSubquery renders "x IN (SELECT ...)" against the given subquery. InSubquery(sub Subquery) Condition // NotInSubquery renders "x NOT IN (SELECT ...)" against the given subquery. NotInSubquery(sub Subquery) Condition IsNull() Condition IsNotNull() Condition Between(lo, hi T) Condition NotBetween(lo, hi T) Condition // Field-to-field comparisons. Each compares this field against another // field or expression, rendering the right operand as an identifier or // expression rather than a bound argument. EQField(other Field[T]) Condition NEField(other Field[T]) Condition GTField(other Field[T]) Condition LTField(other Field[T]) Condition GEField(other Field[T]) Condition LEField(other Field[T]) Condition // Aliasing, ordering, and assignment. As(alias string) Field[T] Asc() OrderField Desc() OrderField Set(v T) Assignment // contains filtered or unexported methods }
Field is a typed column or expression. Comparison methods take a value of the field's own type T, so the compiler rejects mismatched comparisons. Field is the Go counterpart of jOOQ's Field<T>.
func Abs ¶
Abs returns ABS(field), the absolute value of the numeric field, preserving the field's type.
func Avg ¶
Avg returns the AVG aggregate of the given field as a Field[float64], since an average is computed in floating point regardless of the operand type.
func Cast ¶
Cast converts the given field or expression to the named SQL type, rendered as CAST(expr AS sqltype), and returns it as a Field[T]. The SQL type is spliced verbatim, so the caller supplies a spelling valid for the target dialect.
func Coalesce ¶
Coalesce returns the first non-null operand, rendered as COALESCE(a, b, ...). The first operand is a typed field; the remaining operands may be values (which bind) or fields and expressions (which render as identifiers), exactly like the field-operand operator variants elsewhere in the builder.
func Concat ¶
Concat returns a field that concatenates the given parts using the SQL "||" operator. String literals are bound as arguments, while StringField and Field[string] operands render as their column or expression. Both PostgreSQL and SQLite support the "||" operator.
func CountDistinct ¶
CountDistinct returns COUNT(DISTINCT field), counting the distinct non-null values of the field, as a Field[int64].
func CountStar ¶
CountStar returns COUNT(*), counting every row regardless of nulls, as a Field[int64].
func Function ¶
Function builds a typed call to an arbitrary SQL function whose arguments are fields or expressions. The result type T is chosen by the caller, mirroring jOOQ's DSL.function. Each argument renders as its own column or expression rather than binding a value.
func Greatest ¶
Greatest returns the greatest of its operands, rendered as GREATEST(a, b, ...). The first operand is a typed field; the remaining operands may be values (which bind) or fields and expressions (which render as identifiers).
func Least ¶
Least returns the least of its operands, rendered as LEAST(a, b, ...). The first operand is a typed field; the remaining operands may be values (which bind) or fields and expressions (which render as identifiers).
func Length ¶
Length returns LENGTH(field), the character length of the text field, as a Field[int64].
func NewField ¶
NewField builds a typed column field qualified by the owning table's name or alias. Generated table code calls this for each column.
func NullIf ¶
NullIf returns NULLIF(a, b): the SQL NULL when the two operands are equal and the first operand otherwise. The comparison value binds as an argument.
func Raw ¶
Raw is an escape hatch that splices verbatim SQL into the query as a typed field, binding no arguments. The text is emitted exactly as given, so the caller is responsible for any required quoting and for the dialect portability of the fragment.
func RawValue ¶
RawValue is an escape hatch that splices verbatim SQL into the query as a typed field while binding the supplied arguments. Each '?' marker in the SQL text is replaced, in order, by the active dialect's placeholder and consumes one argument from args. Surplus markers or surplus arguments are tolerated: extra markers render with no bound value and extra arguments are ignored, so the marker count and argument count are expected to match.
func Round ¶
Round returns ROUND(field), the numeric field rounded to the nearest integer, preserving the field's type.
func ScalarSubquery ¶
ScalarSubquery adapts a single-column, single-row subquery to a typed Field[T], so it can be projected, compared, or otherwise used where a scalar expression is expected. The element type T is supplied by the caller and is not verified against the subquery's projection.
type ForeignKeyMeta ¶
type ForeignKeyMeta struct {
// Name is the constraint name as stored in the database catalog.
Name string
// Columns are the local column names that participate in the foreign key,
// in the order they appear in the constraint definition.
Columns []string
// RefTable is the unqualified name of the referenced table.
RefTable string
// RefColumns are the referenced column names, aligned positionally with
// Columns.
RefColumns []string
}
ForeignKeyMeta describes a single foreign key constraint discovered during code generation and surfaced on the generated table accessors. It is plain data with no behavior so that the core package remains free of external dependencies and the generated metadata can be inspected at runtime.
type InsertConflictActionStep ¶
type InsertConflictActionStep interface {
DoNothing() InsertReturningStep
DoUpdateSet(assignments ...Assignment) InsertReturningStep
}
InsertConflictActionStep chooses the action for an ON CONFLICT target.
type InsertFinalStep ¶
type InsertFinalStep interface {
SQL() (string, []any, error)
SQLFor(d Dialect) (string, []any, error)
Using(d Dialect) InsertFinalStep
Execute(ctx context.Context, db Querier) (sql.Result, error)
// contains filtered or unexported methods
}
InsertFinalStep is the terminal state.
type InsertOnConflictStep ¶
type InsertOnConflictStep interface {
InsertReturningStep
OnConflict(cols ...AnyField) InsertConflictActionStep
OnConflictDoNothing() InsertReturningStep
OnDuplicateKeyUpdate(assignments ...Assignment) InsertReturningStep
}
InsertOnConflictStep allows attaching conflict-resolution behavior.
type InsertReturningStep ¶
type InsertReturningStep interface {
InsertFinalStep
Returning(cols ...AnyField) InsertFinalStep
}
InsertReturningStep allows a RETURNING clause before terminal execution.
type InsertSetMoreStep ¶
type InsertSetMoreStep interface {
InsertOnConflictStep
Set(a Assignment) InsertSetMoreStep
}
InsertSetMoreStep accepts further column assignments.
type InsertSetStep ¶
type InsertSetStep interface {
Columns(cols ...AnyField) InsertValuesStep
Set(a Assignment) InsertSetMoreStep
DefaultValues() InsertFinalStep
}
InsertSetStep is the entry state after INSERT INTO.
func InsertInto ¶
func InsertInto(t Table) InsertSetStep
InsertInto begins an INSERT into the given table.
type InsertValuesStep ¶
type InsertValuesStep interface {
InsertOnConflictStep
Values(values ...any) InsertValuesStep
// Select supplies the inserted rows from a subquery rather than literal
// value rows. The source SELECT is rendered into the same builder as the
// INSERT, so its bind arguments interleave correctly.
Select(sub Subquery) InsertReturningStep
}
InsertValuesStep accepts one or more value rows, or a SELECT statement whose rows are inserted ("INSERT INTO t (cols) SELECT ...").
type NumericField ¶
type NumericField[T any] interface { Field[T] Add(v T) Field[T] Sub(v T) Field[T] Mul(v T) Field[T] Div(v T) Field[T] ModVal(v T) Field[T] AddField(other Field[T]) Field[T] SubField(other Field[T]) Field[T] MulField(other Field[T]) Field[T] DivField(other Field[T]) Field[T] ModField(other Field[T]) Field[T] // Neg returns a field that negates this expression, rendering "-(expr)". Neg() Field[T] }
NumericField is a Field[T] augmented with arithmetic operators that produce new expression fields. Each operator has a value-taking form that binds its argument and a field-taking form (suffixed "Field") that renders the other field or expression as an identifier instead of binding a value.
func NewNumericField ¶
func NewNumericField[T any](base TableImpl, name string) NumericField[T]
NewNumericField builds a qualified numeric column field.
type OrderField ¶
type OrderField interface {
// NullsFirst orders NULL values before non-NULL values, rendering the
// "NULLS FIRST" qualifier. It returns the same term for chaining.
NullsFirst() OrderField
// NullsLast orders NULL values after non-NULL values, rendering the
// "NULLS LAST" qualifier. It returns the same term for chaining.
NullsLast() OrderField
// contains filtered or unexported methods
}
OrderField is a single ORDER BY term: an expression paired with a sort direction and an optional NULLS ordering. It is produced by Field[T].Asc and Field[T].Desc.
type OverBuilder ¶
type OverBuilder[T any] struct { // contains filtered or unexported fields }
OverBuilder accumulates the PARTITION BY, ORDER BY, and frame components of a window specification. It is returned by WindowField.Over and finalised with End, which yields a typed Field[T].
func (*OverBuilder[T]) End ¶
func (o *OverBuilder[T]) End() Field[T]
End finalises the window specification and returns it as a typed Field[T] usable as a projection column.
func (*OverBuilder[T]) Frame ¶
func (o *OverBuilder[T]) Frame(frame string) *OverBuilder[T]
Frame sets the verbatim frame clause of the window specification, for example "ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW". The clause is spliced verbatim, so the caller supplies a spelling valid for the target dialect; both PostgreSQL and SQLite share the same frame syntax for the common cases.
func (*OverBuilder[T]) OrderBy ¶
func (o *OverBuilder[T]) OrderBy(orders ...OrderField) *OverBuilder[T]
OrderBy adds one or more ORDER BY terms to the window specification, each produced by Field[T].Asc or Field[T].Desc. It returns the same builder for chaining.
func (*OverBuilder[T]) PartitionBy ¶
func (o *OverBuilder[T]) PartitionBy(fields ...AnyField) *OverBuilder[T]
PartitionBy adds one or more PARTITION BY expressions to the window specification. Each field renders as its own column or expression rather than binding a value. It returns the same builder for chaining.
type Querier ¶
type Querier interface {
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}
Querier is the minimal execution surface the library needs. It is satisfied by *sql.DB, *sql.Tx, and *sql.Conn, and by compatible third-party pools such as pgx's stdlib adapter.
type Record1 ¶
type Record1[T1 any] struct { V1 T1 }
Record1 holds one typed column value.
type Record2 ¶
type Record2[T1, T2 any] struct { V1 T1 V2 T2 }
Record2 holds two typed column values.
type Record3 ¶
type Record3[T1, T2, T3 any] struct { V1 T1 V2 T2 V3 T3 }
Record3 holds three typed column values.
type Record4 ¶
type Record4[T1, T2, T3, T4 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 }
Record4 holds four typed column values.
type Record5 ¶
type Record5[T1, T2, T3, T4, T5 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 }
Record5 holds five typed column values.
type Record6 ¶
type Record6[T1, T2, T3, T4, T5, T6 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 }
Record6 holds 6 typed column values.
type Record7 ¶
type Record7[T1, T2, T3, T4, T5, T6, T7 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 }
Record7 holds 7 typed column values.
type Record8 ¶
type Record8[T1, T2, T3, T4, T5, T6, T7, T8 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 }
Record8 holds 8 typed column values.
type Record9 ¶
type Record9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 }
Record9 holds 9 typed column values.
type Record10 ¶
type Record10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 }
Record10 holds 10 typed column values.
type Record11 ¶
type Record11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 }
Record11 holds 11 typed column values.
type Record12 ¶
type Record12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 V12 T12 }
Record12 holds 12 typed column values.
type Record13 ¶
type Record13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 V12 T12 V13 T13 }
Record13 holds 13 typed column values.
type Record14 ¶
type Record14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 V12 T12 V13 T13 V14 T14 }
Record14 holds 14 typed column values.
type Record15 ¶
type Record15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 V12 T12 V13 T13 V14 T14 V15 T15 }
Record15 holds 15 typed column values.
type Record16 ¶
type Record16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 V12 T12 V13 T13 V14 T14 V15 T15 V16 T16 }
Record16 holds 16 typed column values.
type Record17 ¶
type Record17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 V12 T12 V13 T13 V14 T14 V15 T15 V16 T16 V17 T17 }
Record17 holds 17 typed column values.
type Record18 ¶
type Record18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 V12 T12 V13 T13 V14 T14 V15 T15 V16 T16 V17 T17 V18 T18 }
Record18 holds 18 typed column values.
type Record19 ¶
type Record19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 V12 T12 V13 T13 V14 T14 V15 T15 V16 T16 V17 T17 V18 T18 V19 T19 }
Record19 holds 19 typed column values.
type Record20 ¶
type Record20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 V12 T12 V13 T13 V14 T14 V15 T15 V16 T16 V17 T17 V18 T18 V19 T19 V20 T20 }
Record20 holds 20 typed column values.
type Record21 ¶
type Record21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 V12 T12 V13 T13 V14 T14 V15 T15 V16 T16 V17 T17 V18 T18 V19 T19 V20 T20 V21 T21 }
Record21 holds 21 typed column values.
type Record22 ¶
type Record22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22 any] struct { V1 T1 V2 T2 V3 T3 V4 T4 V5 T5 V6 T6 V7 T7 V8 T8 V9 T9 V10 T10 V11 T11 V12 T12 V13 T13 V14 T14 V15 T15 V16 T16 V17 T17 V18 T18 V19 T19 V20 T20 V21 T21 V22 T22 }
Record22 holds 22 typed column values.
type SelectConditionStep ¶
type SelectConditionStep[R any] interface { SelectGroupByStep[R] And(c Condition) SelectConditionStep[R] Or(c Condition) SelectConditionStep[R] }
SelectConditionStep allows extending the WHERE predicate with AND/OR.
type SelectFinalStep ¶
type SelectFinalStep[R any] interface { Subquery // Fetch executes the query and returns every row mapped to R. Fetch(ctx context.Context, db Querier) ([]R, error) // FetchOne returns the single row, the zero value when no row matches, or // ErrTooManyRows when more than one row matches. FetchOne(ctx context.Context, db Querier) (R, error) // FetchSingle returns the single row, sql.ErrNoRows when none matches, or // ErrTooManyRows when more than one matches. FetchSingle(ctx context.Context, db Querier) (R, error) // FetchOptional returns the single row and true, the zero value and false // when no row matches, or ErrTooManyRows when more than one row matches. FetchOptional(ctx context.Context, db Querier) (R, bool, error) // SQL renders the query using the dialect bound to the query (PostgreSQL by // default, or whatever was selected via Using). SQL() (string, []any, error) // SQLFor renders the query using an explicit dialect. SQLFor(d Dialect) (string, []any, error) // Using selects the dialect used by SQL, Fetch, FetchOne, and FetchSingle. Using(d Dialect) SelectFinalStep[R] // Union combines this query with another over the same row type, removing // duplicate rows. Union(other SelectFinalStep[R]) SelectFinalStep[R] // UnionAll combines this query with another over the same row type, keeping // duplicate rows. UnionAll(other SelectFinalStep[R]) SelectFinalStep[R] // Intersect returns the rows common to this query and another over the same // row type. Intersect(other SelectFinalStep[R]) SelectFinalStep[R] // Except returns the rows of this query that do not appear in another over // the same row type. Except(other SelectFinalStep[R]) SelectFinalStep[R] }
SelectFinalStep is the terminal state: render the SQL or execute the query. It embeds Subquery so a fully built SELECT can also serve as a sub-expression.
type SelectFromStep ¶
type SelectFromStep[R any] interface { Subquery From(t Table) SelectJoinStep[R] // Distinct marks the query as SELECT DISTINCT. It is idempotent and may be // called before From. Distinct() SelectFromStep[R] }
SelectFromStep is the state immediately after the projection is chosen. Distinct may be applied here, before the FROM clause, and returns the same step so the projection can still be followed by From. It embeds Subquery so a SELECT may be used as a sub-expression (EXISTS, IN, or scalar) at any point in its construction.
func Select1 ¶
func Select1[T1 any](f1 Field[T1]) SelectFromStep[Record1[T1]]
Select1 begins a SELECT projecting one typed column.
func Select2 ¶
func Select2[T1, T2 any](f1 Field[T1], f2 Field[T2]) SelectFromStep[Record2[T1, T2]]
Select2 begins a SELECT projecting two typed columns.
func Select3 ¶
func Select3[T1, T2, T3 any](f1 Field[T1], f2 Field[T2], f3 Field[T3]) SelectFromStep[Record3[T1, T2, T3]]
Select3 begins a SELECT projecting three typed columns.
func Select4 ¶
func Select4[T1, T2, T3, T4 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4]) SelectFromStep[Record4[T1, T2, T3, T4]]
Select4 begins a SELECT projecting four typed columns.
func Select5 ¶
func Select5[T1, T2, T3, T4, T5 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5]) SelectFromStep[Record5[T1, T2, T3, T4, T5]]
Select5 begins a SELECT projecting five typed columns.
func Select6 ¶
func Select6[T1, T2, T3, T4, T5, T6 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6]) SelectFromStep[Record6[T1, T2, T3, T4, T5, T6]]
Select6 begins a SELECT projecting 6 typed columns.
func Select7 ¶
func Select7[T1, T2, T3, T4, T5, T6, T7 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7]) SelectFromStep[Record7[T1, T2, T3, T4, T5, T6, T7]]
Select7 begins a SELECT projecting 7 typed columns.
func Select8 ¶
func Select8[T1, T2, T3, T4, T5, T6, T7, T8 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8]) SelectFromStep[Record8[T1, T2, T3, T4, T5, T6, T7, T8]]
Select8 begins a SELECT projecting 8 typed columns.
func Select9 ¶
func Select9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9]) SelectFromStep[Record9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]
Select9 begins a SELECT projecting 9 typed columns.
func Select10 ¶
func Select10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10]) SelectFromStep[Record10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]
Select10 begins a SELECT projecting 10 typed columns.
func Select11 ¶
func Select11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11]) SelectFromStep[Record11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]]
Select11 begins a SELECT projecting 11 typed columns.
func Select12 ¶
func Select12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11], f12 Field[T12]) SelectFromStep[Record12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]]
Select12 begins a SELECT projecting 12 typed columns.
func Select13 ¶
func Select13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11], f12 Field[T12], f13 Field[T13]) SelectFromStep[Record13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]]
Select13 begins a SELECT projecting 13 typed columns.
func Select14 ¶
func Select14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11], f12 Field[T12], f13 Field[T13], f14 Field[T14]) SelectFromStep[Record14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]]
Select14 begins a SELECT projecting 14 typed columns.
func Select15 ¶
func Select15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11], f12 Field[T12], f13 Field[T13], f14 Field[T14], f15 Field[T15]) SelectFromStep[Record15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]]
Select15 begins a SELECT projecting 15 typed columns.
func Select16 ¶
func Select16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11], f12 Field[T12], f13 Field[T13], f14 Field[T14], f15 Field[T15], f16 Field[T16]) SelectFromStep[Record16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]]
Select16 begins a SELECT projecting 16 typed columns.
func Select17 ¶
func Select17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11], f12 Field[T12], f13 Field[T13], f14 Field[T14], f15 Field[T15], f16 Field[T16], f17 Field[T17]) SelectFromStep[Record17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]]
Select17 begins a SELECT projecting 17 typed columns.
func Select18 ¶
func Select18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11], f12 Field[T12], f13 Field[T13], f14 Field[T14], f15 Field[T15], f16 Field[T16], f17 Field[T17], f18 Field[T18]) SelectFromStep[Record18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]]
Select18 begins a SELECT projecting 18 typed columns.
func Select19 ¶
func Select19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11], f12 Field[T12], f13 Field[T13], f14 Field[T14], f15 Field[T15], f16 Field[T16], f17 Field[T17], f18 Field[T18], f19 Field[T19]) SelectFromStep[Record19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]]
Select19 begins a SELECT projecting 19 typed columns.
func Select20 ¶
func Select20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11], f12 Field[T12], f13 Field[T13], f14 Field[T14], f15 Field[T15], f16 Field[T16], f17 Field[T17], f18 Field[T18], f19 Field[T19], f20 Field[T20]) SelectFromStep[Record20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]]
Select20 begins a SELECT projecting 20 typed columns.
func Select21 ¶
func Select21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11], f12 Field[T12], f13 Field[T13], f14 Field[T14], f15 Field[T15], f16 Field[T16], f17 Field[T17], f18 Field[T18], f19 Field[T19], f20 Field[T20], f21 Field[T21]) SelectFromStep[Record21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]]
Select21 begins a SELECT projecting 21 typed columns.
func Select22 ¶
func Select22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22 any](f1 Field[T1], f2 Field[T2], f3 Field[T3], f4 Field[T4], f5 Field[T5], f6 Field[T6], f7 Field[T7], f8 Field[T8], f9 Field[T9], f10 Field[T10], f11 Field[T11], f12 Field[T12], f13 Field[T13], f14 Field[T14], f15 Field[T15], f16 Field[T16], f17 Field[T17], f18 Field[T18], f19 Field[T19], f20 Field[T20], f21 Field[T21], f22 Field[T22]) SelectFromStep[Record22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]]
Select22 begins a SELECT projecting 22 typed columns.
type SelectGroupByStep ¶
type SelectGroupByStep[R any] interface { SelectOrderByStep[R] GroupBy(fields ...AnyField) SelectHavingStep[R] }
SelectGroupByStep allows a GROUP BY clause or skipping to ORDER BY and limit.
type SelectHavingStep ¶
type SelectHavingStep[R any] interface { SelectOrderByStep[R] Having(c Condition) SelectOrderByStep[R] }
SelectHavingStep allows a HAVING clause after GROUP BY.
type SelectJoinStep ¶
type SelectJoinStep[R any] interface { SelectWhereStep[R] Join(t Table) SelectOnStep[R] InnerJoin(t Table) SelectOnStep[R] LeftJoin(t Table) SelectOnStep[R] RightJoin(t Table) SelectOnStep[R] }
SelectJoinStep allows joining further tables or, by embedding SelectWhereStep, skipping straight to WHERE and beyond.
type SelectLimitStep ¶
type SelectLimitStep[R any] interface { SelectLockStep[R] Limit(n int64) SelectLimitStep[R] Offset(n int64) SelectLimitStep[R] }
SelectLimitStep allows a LIMIT and/or OFFSET clause, a row-locking clause, or terminal execution. Both Limit and Offset return SelectLimitStep so they may be chained in either order or used independently (a bare OFFSET is legal).
type SelectLockStep ¶
type SelectLockStep[R any] interface { SelectFinalStep[R] // ForUpdate adds a FOR UPDATE locking clause to the query. ForUpdate() SelectLockStep[R] ForShare() SelectLockStep[R] // SkipLocked appends SKIP LOCKED to the locking clause, so locked rows are // skipped rather than waited on. It is meaningful only after ForUpdate or // ForShare. SkipLocked() SelectLockStep[R] }
SelectLockStep allows a row-locking clause (FOR UPDATE / FOR SHARE, optionally SKIP LOCKED) after ORDER BY, LIMIT, and OFFSET, or terminal execution. The locking clause is rendered for PostgreSQL and silently omitted for SQLite, which has no such clause.
type SelectOnStep ¶
type SelectOnStep[R any] interface { On(c Condition) SelectJoinStep[R] }
SelectOnStep requires the join condition before any further clause.
type SelectOrderByStep ¶
type SelectOrderByStep[R any] interface { SelectLimitStep[R] OrderBy(orders ...OrderField) SelectLimitStep[R] }
SelectOrderByStep allows an ORDER BY clause or skipping to limit.
type SelectWhereStep ¶
type SelectWhereStep[R any] interface { SelectGroupByStep[R] Where(c Condition) SelectConditionStep[R] }
SelectWhereStep allows a WHERE clause or, by embedding SelectGroupByStep, skipping it.
type StringField ¶
type StringField interface {
Field[string]
Like(pattern string) Condition
NotLike(pattern string) Condition
// ILike performs a case-insensitive match. It maps to ILIKE on PostgreSQL
// and to a plain LIKE on SQLite, whose LIKE is already case-insensitive for
// ASCII text.
ILike(pattern string) Condition
// Concat returns a field that concatenates this field with the given parts
// using the SQL "||" operator. String literals are bound as arguments,
// while StringField and Field[string] operands render as their column or
// expression.
Concat(others ...any) Field[string]
}
StringField is a Field[string] augmented with pattern-matching predicates that only make sense for text columns.
func NewStringField ¶
func NewStringField(base TableImpl, name string) StringField
NewStringField builds a qualified text column field.
type Subquery ¶
type Subquery interface {
// contains filtered or unexported methods
}
Subquery is a SELECT statement usable as a sub-expression. It is sealed through the embedded node interface, so only this package can provide implementations; the concrete *selectBuilder produced by the SelectN constructors satisfies it. The interface keeps the subquery-taking API typed while preserving the seal on the SELECT step chain.
type Table ¶
type Table interface {
// TableName returns the unqualified table name.
TableName() string
// contains filtered or unexported methods
}
Table is a SQL table reference usable in FROM and JOIN clauses. Generated table types embed the exported TableImpl base and expose typed Field columns.
Aliasing is intentionally not part of this interface: a concrete table type declares its own As(alias) method returning its own concrete type, so that the aliased table still exposes typed columns (qualified by the alias). The aliased value continues to satisfy Table for use in FROM and JOIN.
type TableImpl ¶
type TableImpl struct {
// contains filtered or unexported fields
}
TableImpl is the embeddable base for generated table types. It renders the table reference in a FROM or JOIN position, including an optional schema and alias. External generated code embeds TableImpl, which supplies the unexported render method and thereby satisfies the sealed Table interface.
func (TableImpl) Qualifier ¶
Qualifier returns the identifier used to qualify this table's columns: the alias when aliased, otherwise the table name.
func (TableImpl) WithAlias ¶
WithAlias returns a copy of the table base carrying the given alias. Generated table types call this from their own As method, then rebuild their typed columns so that each column is qualified by the alias.
func (TableImpl) WithSchema ¶
WithSchema returns a copy of the table base qualified by the given schema.
type UniqueKeyMeta ¶
type UniqueKeyMeta struct {
// Name is the constraint name as stored in the database catalog.
Name string
// Columns are the column names that participate in the unique constraint,
// in the order they appear in the constraint definition.
Columns []string
}
UniqueKeyMeta describes a single unique constraint discovered during code generation. Like ForeignKeyMeta it is plain data with no behavior.
type UpdateConditionStep ¶
type UpdateConditionStep interface {
UpdateReturningStep
And(c Condition) UpdateConditionStep
Or(c Condition) UpdateConditionStep
}
UpdateConditionStep allows extending the WHERE predicate.
type UpdateFinalStep ¶
type UpdateFinalStep interface {
SQL() (string, []any, error)
SQLFor(d Dialect) (string, []any, error)
Using(d Dialect) UpdateFinalStep
Execute(ctx context.Context, db Querier) (sql.Result, error)
// contains filtered or unexported methods
}
UpdateFinalStep is the terminal state.
type UpdateReturningStep ¶
type UpdateReturningStep interface {
UpdateFinalStep
Returning(cols ...AnyField) UpdateFinalStep
}
UpdateReturningStep allows a RETURNING clause before terminal execution.
type UpdateSetMoreStep ¶
type UpdateSetMoreStep interface {
UpdateWhereStep
Set(a Assignment) UpdateSetMoreStep
// From joins a further table into the UPDATE through a FROM clause, rendered
// before WHERE. Supported by PostgreSQL and recent SQLite.
From(t Table) UpdateWhereStep
}
UpdateSetMoreStep accepts further assignments, a FROM clause, or a WHERE clause.
type UpdateSetStep ¶
type UpdateSetStep interface {
Set(a Assignment) UpdateSetMoreStep
}
UpdateSetStep is the entry state after UPDATE table.
type UpdateWhereStep ¶
type UpdateWhereStep interface {
UpdateReturningStep
Where(c Condition) UpdateConditionStep
}
UpdateWhereStep allows a WHERE clause or terminal execution.
type WindowField ¶
type WindowField[T any] struct { // contains filtered or unexported fields }
WindowField is a window-function expression awaiting its window specification. It is produced by the ranking, value, and windowed-aggregate constructors and finalised through Over, which yields a typed Field[T] usable as a projection column. When Over is not called the WindowField is not itself a Field; callers must always finalise it with Over().End(), even when the window is empty.
func AvgOver ¶
func AvgOver[T any](f Field[T]) WindowField[float64]
AvgOver returns the AVG(field) aggregate evaluated as a window function, as a WindowField[float64], since an average is computed in floating point regardless of the operand type.
func CountOver ¶
func CountOver(f AnyField) WindowField[int64]
CountOver returns the COUNT(field) aggregate evaluated as a window function, as a WindowField[int64].
func DenseRank ¶
func DenseRank() WindowField[int64]
DenseRank returns the DENSE_RANK() window function, assigning each row a rank within its window without gaps after ties, as a WindowField[int64].
func FirstValue ¶
func FirstValue[T any](f Field[T]) WindowField[T]
FirstValue returns the FIRST_VALUE(field) window function, the value of the field in the first row of the window, preserving the field's type.
func Lag ¶
func Lag[T any](f Field[T]) WindowField[T]
Lag returns the LAG(field) window function, accessing the value of the field in a preceding row of the window, preserving the field's type.
func LastValue ¶
func LastValue[T any](f Field[T]) WindowField[T]
LastValue returns the LAST_VALUE(field) window function, the value of the field in the last row of the window, preserving the field's type.
func Lead ¶
func Lead[T any](f Field[T]) WindowField[T]
Lead returns the LEAD(field) window function, accessing the value of the field in a following row of the window, preserving the field's type.
func Rank ¶
func Rank() WindowField[int64]
Rank returns the RANK() window function, assigning each row a rank within its window with gaps after ties, as a WindowField[int64].
func RowNumber ¶
func RowNumber() WindowField[int64]
RowNumber returns the ROW_NUMBER() window function, assigning each row a distinct sequential number within its window, as a WindowField[int64].
func SumOver ¶
func SumOver[T any](f Field[T]) WindowField[T]
SumOver returns the SUM(field) aggregate evaluated as a window function, preserving the field's type.
func (WindowField[T]) Over ¶
func (w WindowField[T]) Over() *OverBuilder[T]
Over begins the window specification for this window function, returning a builder on which PartitionBy, OrderBy, and Frame may be set before End finalises the expression.
Source Files
¶
- assignment.go
- ast.go
- batch.go
- builder.go
- condition.go
- delete.go
- dialect.go
- doc.go
- errors.go
- exec.go
- fetch_into.go
- field.go
- function.go
- insert.go
- keymeta.go
- locking.go
- node.go
- order.go
- raw.go
- record.go
- record_gen.go
- returning_into.go
- select.go
- select_gen.go
- select_record.go
- setop.go
- string_field.go
- subquery.go
- table.go
- tx.go
- update.go
- window.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gooq-gen
command
Command gooq-gen generates typed table accessors for the jooq query builder by introspecting a live database schema through the standard information_schema catalog.
|
Command gooq-gen generates typed table accessors for the jooq query builder by introspecting a live database schema through the standard information_schema catalog. |
|
Package codegen introspects a PostgreSQL database and generates typed table accessors compatible with the jooq query builder package.
|
Package codegen introspects a PostgreSQL database and generates typed table accessors compatible with the jooq query builder package. |
|
Command example demonstrates the jooq-for-go query builder against the generated table accessors in ./internal/db.
|
Command example demonstrates the jooq-for-go query builder against the generated table accessors in ./internal/db. |
|
internal
|
|
|
gen
command
Command gen produces the repetitive higher-arity Record and Select code for the jooq package.
|
Command gen produces the repetitive higher-arity Record and Select code for the jooq package. |