Documentation
¶
Index ¶
- func Alias(table *schema.TableDef, alias string) *aliasedTable
- type ColRef
- type Condition
- func And(conds ...Condition) Condition
- func Between(col colRef, low, high any) Condition
- func ContainedBy(col colRef, val any) Condition
- func Contains(col colRef, val any) Condition
- func Eq(col colRef, val any) Condition
- func EqAny(col colRef, sub Subquery) Condition
- func Exists(sub Subquery) Condition
- func Gt(col colRef, val any) Condition
- func Gte(col colRef, val any) Condition
- func ILike(col colRef, pattern string) Condition
- func In(col colRef, vals ...any) Condition
- func IsNotNull(col colRef) Condition
- func IsNull(col colRef) Condition
- func KeyExists(col colRef, key any) Condition
- func Like(col colRef, pattern string) Condition
- func Lt(col colRef, val any) Condition
- func Lte(col colRef, val any) Condition
- func Neq(col colRef, val any) Condition
- func NeqAll(col colRef, sub Subquery) Condition
- func Not(cond Condition) Condition
- func NotBetween(col colRef, low, high any) Condition
- func NotIn(col colRef, vals ...any) Condition
- func Or(conds ...Condition) Condition
- func Raw(expr string, args ...any) Condition
- type DeleteBuilder
- func (d *DeleteBuilder) Limit(n int) *DeleteBuilder
- func (d *DeleteBuilder) OrderBy(cols []string, dir OrderDir) *DeleteBuilder
- func (d *DeleteBuilder) OrderByNulls(cols []string, dir OrderDir, nulls NullsOrder) *DeleteBuilder
- func (d *DeleteBuilder) Returning(cols ...string) *DeleteBuilder
- func (d *DeleteBuilder) Run(ctx context.Context, exec db.Executor) (int64, error)
- func (d *DeleteBuilder) SQL() (string, []any)
- func (d *DeleteBuilder) Scan(ctx context.Context, exec db.Executor, dest ...any) error
- func (d *DeleteBuilder) Where(c Condition) *DeleteBuilder
- type InsertBuilder
- func (i *InsertBuilder) OnConflictDoNothing(targets ...string) *InsertBuilder
- func (i *InsertBuilder) OnConflictDoUpdate(targets []string, updateVals map[string]any) *InsertBuilder
- func (i *InsertBuilder) OnConflictExcluded(targets []string, cols ...string) *InsertBuilder
- func (i *InsertBuilder) Returning(cols ...string) *InsertBuilder
- func (i *InsertBuilder) Run(ctx context.Context, exec db.Executor) error
- func (i *InsertBuilder) SQL() (string, []any)
- func (i *InsertBuilder) Scan(ctx context.Context, exec db.Executor, dest ...any) error
- func (i *InsertBuilder) ScanInto[T any](ctx context.Context, exec db.Executor) (T, error)
- func (i *InsertBuilder) Values(rows ...map[string]any) *InsertBuilder
- type JoinKind
- type NullsOrder
- type OrderBy
- type OrderDir
- type SelectBuilder
- func (q *SelectBuilder[T]) All(ctx context.Context, exec db.Executor) ([]T, error)
- func (q *SelectBuilder[T]) Count(ctx context.Context, exec db.Executor) (int64, error)
- func (q *SelectBuilder[T]) CountDistinct(ctx context.Context, exec db.Executor, col colRef) (int64, error)
- func (q *SelectBuilder[T]) CrossJoin(table namedTable) *SelectBuilder[T]
- func (q *SelectBuilder[T]) Distinct() *SelectBuilder[T]
- func (q *SelectBuilder[T]) Except(sub Subquery) *SelectBuilder[T]
- func (q *SelectBuilder[T]) First(ctx context.Context, exec db.Executor) (*T, error)
- func (q *SelectBuilder[T]) ForShare() *SelectBuilder[T]
- func (q *SelectBuilder[T]) ForUpdate() *SelectBuilder[T]
- func (q *SelectBuilder[T]) From(table namedTable) *SelectBuilder[T]
- func (q *SelectBuilder[T]) FullJoin(table namedTable, on Condition) *SelectBuilder[T]
- func (q *SelectBuilder[T]) GroupBy(cols ...string) *SelectBuilder[T]
- func (q *SelectBuilder[T]) Having(c Condition) *SelectBuilder[T]
- func (q *SelectBuilder[T]) InnerJoin(table namedTable, on Condition) *SelectBuilder[T]
- func (q *SelectBuilder[T]) Intersect(sub Subquery) *SelectBuilder[T]
- func (q *SelectBuilder[T]) LeftJoin(table namedTable, on Condition) *SelectBuilder[T]
- func (q *SelectBuilder[T]) Limit(n int) *SelectBuilder[T]
- func (q *SelectBuilder[T]) NoWait() *SelectBuilder[T]
- func (q *SelectBuilder[T]) Offset(n int) *SelectBuilder[T]
- func (q *SelectBuilder[T]) OrderBy(cols []string, dir OrderDir) *SelectBuilder[T]
- func (q *SelectBuilder[T]) OrderByNulls(cols []string, dir OrderDir, nulls NullsOrder) *SelectBuilder[T]
- func (q *SelectBuilder[T]) RightJoin(table namedTable, on Condition) *SelectBuilder[T]
- func (q *SelectBuilder[T]) SQL() (string, []any)
- func (q *SelectBuilder[T]) SkipLocked() *SelectBuilder[T]
- func (q *SelectBuilder[T]) Union(sub Subquery) *SelectBuilder[T]
- func (q *SelectBuilder[T]) UnionAll(sub Subquery) *SelectBuilder[T]
- func (q *SelectBuilder[T]) Where(c Condition) *SelectBuilder[T]
- func (q *SelectBuilder[T]) With(name string, sub Subquery) *SelectBuilder[T]
- type Subquery
- type UpdateBuilder
- func (u *UpdateBuilder) Limit(n int) *UpdateBuilder
- func (u *UpdateBuilder) OrderBy(cols []string, dir OrderDir) *UpdateBuilder
- func (u *UpdateBuilder) OrderByNulls(cols []string, dir OrderDir, nulls NullsOrder) *UpdateBuilder
- func (u *UpdateBuilder) Returning(cols ...string) *UpdateBuilder
- func (u *UpdateBuilder) Run(ctx context.Context, exec db.Executor) (int64, error)
- func (u *UpdateBuilder) SQL() (string, []any)
- func (u *UpdateBuilder) Scan(ctx context.Context, exec db.Executor, dest ...any) error
- func (u *UpdateBuilder) ScanInto[T any](ctx context.Context, exec db.Executor) (T, error)
- func (u *UpdateBuilder) Set(vals map[string]any) *UpdateBuilder
- func (u *UpdateBuilder) Where(c Condition) *UpdateBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ColRef ¶ added in v0.1.2
type ColRef struct {
// contains filtered or unexported fields
}
type Condition ¶
func ContainedBy ¶ added in v0.1.3
ContainedBy renders `col <@ $n` (the JSON value is contained by the operand).
func NotBetween ¶ added in v0.1.3
NotBetween renders `col NOT BETWEEN $n AND $n+1`.
type DeleteBuilder ¶
type DeleteBuilder struct {
// contains filtered or unexported fields
}
func Delete ¶
func Delete(table namedTable) *DeleteBuilder
func (*DeleteBuilder) Limit ¶ added in v0.1.3
func (d *DeleteBuilder) Limit(n int) *DeleteBuilder
Limit caps how many rows the delete removes (PostgreSQL DELETE ... LIMIT n).
func (*DeleteBuilder) OrderBy ¶ added in v0.1.3
func (d *DeleteBuilder) OrderBy(cols []string, dir OrderDir) *DeleteBuilder
func (*DeleteBuilder) OrderByNulls ¶ added in v0.1.3
func (d *DeleteBuilder) OrderByNulls(cols []string, dir OrderDir, nulls NullsOrder) *DeleteBuilder
func (*DeleteBuilder) Returning ¶
func (d *DeleteBuilder) Returning(cols ...string) *DeleteBuilder
func (*DeleteBuilder) SQL ¶
func (d *DeleteBuilder) SQL() (string, []any)
func (*DeleteBuilder) Where ¶
func (d *DeleteBuilder) Where(c Condition) *DeleteBuilder
type InsertBuilder ¶
type InsertBuilder struct {
// contains filtered or unexported fields
}
func Insert ¶
func Insert(table namedTable) *InsertBuilder
func (*InsertBuilder) OnConflictDoNothing ¶ added in v0.1.2
func (i *InsertBuilder) OnConflictDoNothing(targets ...string) *InsertBuilder
func (*InsertBuilder) OnConflictDoUpdate ¶ added in v0.1.2
func (i *InsertBuilder) OnConflictDoUpdate(targets []string, updateVals map[string]any) *InsertBuilder
func (*InsertBuilder) OnConflictExcluded ¶ added in v0.1.2
func (i *InsertBuilder) OnConflictExcluded(targets []string, cols ...string) *InsertBuilder
func (*InsertBuilder) Returning ¶
func (i *InsertBuilder) Returning(cols ...string) *InsertBuilder
func (*InsertBuilder) SQL ¶
func (i *InsertBuilder) SQL() (string, []any)
func (*InsertBuilder) Values ¶
func (i *InsertBuilder) Values(rows ...map[string]any) *InsertBuilder
type NullsOrder ¶ added in v0.1.3
type NullsOrder string
const ( NullsFirst NullsOrder = "NULLS FIRST" NullsLast NullsOrder = "NULLS LAST" )
type SelectBuilder ¶
type SelectBuilder[T any] struct { // contains filtered or unexported fields }
func Select ¶
func Select[T any](cols ...colRef) *SelectBuilder[T]
func (*SelectBuilder[T]) CountDistinct ¶ added in v0.1.3
func (q *SelectBuilder[T]) CountDistinct(ctx context.Context, exec db.Executor, col colRef) (int64, error)
CountDistinct counts the distinct values of col across the query result: `SELECT COUNT(DISTINCT col) FROM (<query>)`.
func (*SelectBuilder[T]) CrossJoin ¶
func (q *SelectBuilder[T]) CrossJoin(table namedTable) *SelectBuilder[T]
func (*SelectBuilder[T]) Distinct ¶
func (q *SelectBuilder[T]) Distinct() *SelectBuilder[T]
func (*SelectBuilder[T]) Except ¶ added in v0.1.3
func (q *SelectBuilder[T]) Except(sub Subquery) *SelectBuilder[T]
func (*SelectBuilder[T]) ForShare ¶ added in v0.1.3
func (q *SelectBuilder[T]) ForShare() *SelectBuilder[T]
ForShare adds `FOR SHARE` (row-level shared lock).
func (*SelectBuilder[T]) ForUpdate ¶ added in v0.1.3
func (q *SelectBuilder[T]) ForUpdate() *SelectBuilder[T]
ForUpdate adds `FOR UPDATE` (row-level lock).
func (*SelectBuilder[T]) From ¶
func (q *SelectBuilder[T]) From(table namedTable) *SelectBuilder[T]
func (*SelectBuilder[T]) FullJoin ¶
func (q *SelectBuilder[T]) FullJoin(table namedTable, on Condition) *SelectBuilder[T]
func (*SelectBuilder[T]) GroupBy ¶
func (q *SelectBuilder[T]) GroupBy(cols ...string) *SelectBuilder[T]
func (*SelectBuilder[T]) Having ¶
func (q *SelectBuilder[T]) Having(c Condition) *SelectBuilder[T]
func (*SelectBuilder[T]) InnerJoin ¶
func (q *SelectBuilder[T]) InnerJoin(table namedTable, on Condition) *SelectBuilder[T]
func (*SelectBuilder[T]) Intersect ¶ added in v0.1.3
func (q *SelectBuilder[T]) Intersect(sub Subquery) *SelectBuilder[T]
func (*SelectBuilder[T]) LeftJoin ¶
func (q *SelectBuilder[T]) LeftJoin(table namedTable, on Condition) *SelectBuilder[T]
func (*SelectBuilder[T]) Limit ¶
func (q *SelectBuilder[T]) Limit(n int) *SelectBuilder[T]
func (*SelectBuilder[T]) NoWait ¶ added in v0.1.3
func (q *SelectBuilder[T]) NoWait() *SelectBuilder[T]
NoWait makes a locking clause fail immediately if rows are locked.
func (*SelectBuilder[T]) Offset ¶
func (q *SelectBuilder[T]) Offset(n int) *SelectBuilder[T]
func (*SelectBuilder[T]) OrderBy ¶
func (q *SelectBuilder[T]) OrderBy(cols []string, dir OrderDir) *SelectBuilder[T]
func (*SelectBuilder[T]) OrderByNulls ¶ added in v0.1.3
func (q *SelectBuilder[T]) OrderByNulls(cols []string, dir OrderDir, nulls NullsOrder) *SelectBuilder[T]
OrderByNulls is OrderBy with an explicit NULLS FIRST / NULLS LAST placement.
func (*SelectBuilder[T]) RightJoin ¶
func (q *SelectBuilder[T]) RightJoin(table namedTable, on Condition) *SelectBuilder[T]
func (*SelectBuilder[T]) SQL ¶
func (q *SelectBuilder[T]) SQL() (string, []any)
func (*SelectBuilder[T]) SkipLocked ¶ added in v0.1.3
func (q *SelectBuilder[T]) SkipLocked() *SelectBuilder[T]
SkipLocked skips rows locked by other transactions (SELECT ... FOR UPDATE SKIP LOCKED).
func (*SelectBuilder[T]) Union ¶ added in v0.1.3
func (q *SelectBuilder[T]) Union(sub Subquery) *SelectBuilder[T]
func (*SelectBuilder[T]) UnionAll ¶ added in v0.1.3
func (q *SelectBuilder[T]) UnionAll(sub Subquery) *SelectBuilder[T]
func (*SelectBuilder[T]) Where ¶
func (q *SelectBuilder[T]) Where(c Condition) *SelectBuilder[T]
func (*SelectBuilder[T]) With ¶ added in v0.1.3
func (q *SelectBuilder[T]) With(name string, sub Subquery) *SelectBuilder[T]
With prepends a common table expression: `WITH name AS (SELECT ...)`.
type Subquery ¶ added in v0.1.3
type Subquery struct {
// contains filtered or unexported fields
}
func Sub ¶ added in v0.1.3
func Sub[T any](b *SelectBuilder[T]) Subquery
Sub captures a SelectBuilder as a reusable Subquery. The inner generic row type is never scanned into
type UpdateBuilder ¶
type UpdateBuilder struct {
// contains filtered or unexported fields
}
func Update ¶
func Update(table namedTable) *UpdateBuilder
func (*UpdateBuilder) Limit ¶ added in v0.1.3
func (u *UpdateBuilder) Limit(n int) *UpdateBuilder
Limit caps how many rows the update touches (PostgreSQL UPDATE ... LIMIT n).
func (*UpdateBuilder) OrderBy ¶ added in v0.1.3
func (u *UpdateBuilder) OrderBy(cols []string, dir OrderDir) *UpdateBuilder
func (*UpdateBuilder) OrderByNulls ¶ added in v0.1.3
func (u *UpdateBuilder) OrderByNulls(cols []string, dir OrderDir, nulls NullsOrder) *UpdateBuilder
func (*UpdateBuilder) Returning ¶
func (u *UpdateBuilder) Returning(cols ...string) *UpdateBuilder
func (*UpdateBuilder) SQL ¶
func (u *UpdateBuilder) SQL() (string, []any)
func (*UpdateBuilder) Set ¶
func (u *UpdateBuilder) Set(vals map[string]any) *UpdateBuilder
Set assigns columns. Later calls overwrite earlier values for the same column instead of appending a duplicate SET clause. Values may be:
- literals (bound as placeholders): Set(map[string]any{"name": "foo"})
- column references (rendered as-is): Set(map[string]any{"count": seq})
- subqueries (rendered as `col = (SELECT ...)`): Set(map[string]any{"total": sub})
func (*UpdateBuilder) Where ¶
func (u *UpdateBuilder) Where(c Condition) *UpdateBuilder