Documentation
¶
Overview ¶
Package funq provides the runtime kernel and public generic types used by Funq-generated clients.
Index ¶
- Constants
- Variables
- func ContextConstraintLookup(ctx context.Context) (dialect.ConstraintLookup, bool)
- func ContextSensitivePositions(ctx context.Context) ([]int, bool)
- func IsRetryable(err error) bool
- func NamedExec(ctx context.Context, drv Driver, sql string, args []any, ...) (int64, error)
- func NamedFirst[T any](ctx context.Context, drv Driver, sql string, args []any, ...) (*T, error)
- func NamedIterate[T any](ctx context.Context, drv Driver, sql string, args []any, fn func(T) error, ...) error
- func NamedOne[T any](ctx context.Context, drv Driver, sql string, args []any, ...) (*T, error)
- func NamedQuery[T any](ctx context.Context, drv Driver, sql string, args []any, ...) ([]T, error)
- func Observe(ctx context.Context, sql string, args []any, err error, dur time.Duration)
- func RedactArgs(args []any, sensitivePos []int) []any
- func RunInSavepoint(ctx context.Context, tx TxDriver, fn func(TxDriver) error, ...) (err error)
- func RunInTx(ctx context.Context, d Driver, opts TxOptions, fn func(TxDriver) error) (err error)
- func RunInTxRetry(ctx context.Context, d Driver, txOptions TxOptions, retry RetryOptions, ...) error
- func RunInTxWithRetry(ctx context.Context, d Driver, txOptions TxOptions, retry RetryOptions, ...) error
- func Scan[T any, Q scanQuery](ctx context.Context, q Q) ([]T, error)
- func ScanRows[T any](rows Rows, strict bool) ([]T, error)
- func WithConstraintLookup(ctx context.Context, lookup dialect.ConstraintLookup) context.Context
- func WithContextObserver(ctx context.Context, obs QueryObserver) context.Context
- func WithNamedQueryMetadata(ctx context.Context, entity string, op Operation, readOnly bool, ...) context.Context
- func WithQueryMetadata(ctx context.Context, entity string, op Operation) context.Context
- func WithSensitivePositions(ctx context.Context, positions []int) context.Context
- type Annotation
- type ArrayCol
- func (c ArrayCol) As(alias string) SelectExpr
- func (c ArrayCol) Asc() OrderTerm[T]
- func (c ArrayCol[T, E]) Contains(v []E) Pred[T]
- func (c ArrayCol) Desc() OrderTerm[T]
- func (c ArrayCol[T, E]) Eq(v []E) Pred[T]
- func (c ArrayCol) Expr() MutationExpr
- func (c ArrayCol[T, E]) Has(v E) Pred[T]
- func (c ArrayCol) IsNull() Pred[T]
- func (c ArrayCol) NotNull() Pred[T]
- func (c ArrayCol[T, E]) Overlaps(v []E) Pred[T]
- func (c ArrayCol) Ref() ColumnRef
- type Assignment
- type BoolCol
- func (c BoolCol) As(alias string) SelectExpr
- func (c BoolCol) Asc() OrderTerm[T]
- func (c BoolCol) Desc() OrderTerm[T]
- func (c BoolCol[T]) Eq(v bool) Pred[T]
- func (c BoolCol) Expr() MutationExpr
- func (c BoolCol[T]) IsFalse() Pred[T]
- func (c BoolCol) IsNull() Pred[T]
- func (c BoolCol[T]) IsTrue() Pred[T]
- func (c BoolCol) NotNull() Pred[T]
- func (c BoolCol) Ref() ColumnRef
- type BulkInsertBuilder
- func (b *BulkInsertBuilder[T]) Add(row BulkRow) *BulkInsertBuilder[T]
- func (b *BulkInsertBuilder[T]) AddRow(assignments ...Assignment) *BulkInsertBuilder[T]
- func (b *BulkInsertBuilder[T]) BatchSize(size int) *BulkInsertBuilder[T]
- func (b *BulkInsertBuilder[T]) Batches() ([]MutationBatch, error)
- func (b *BulkInsertBuilder[T]) Exec(ctx context.Context) (int64, error)
- func (b *BulkInsertBuilder[T]) ParameterLimit(limit int) *BulkInsertBuilder[T]
- type BulkRow
- type CTE
- type ColumnRef
- type Config
- type ConflictTarget
- type ConstraintError
- type ConstraintKind
- type CopyBuilder
- type CopyDriver
- type CopySource
- type CreateBuilder
- func (b *CreateBuilder[T]) Clear(column string) *CreateBuilder[T]
- func (b *CreateBuilder[T]) ClearSensitive(column string) *CreateBuilder[T]
- func (b *CreateBuilder[T]) Require(columns ...string) *CreateBuilder[T]
- func (b *CreateBuilder[T]) Returning(exprs ...SelectExpr) *CreateBuilder[T]
- func (b *CreateBuilder[T]) SQL() (string, []any, error)
- func (b *CreateBuilder[T]) Save(ctx context.Context) (*T, error)
- func (b *CreateBuilder[T]) Set(column string, value any) *CreateBuilder[T]
- func (b *CreateBuilder[T]) SetExpr(column string, expression MutationExpr) *CreateBuilder[T]
- func (b *CreateBuilder[T]) SetNillable(column string, value any) *CreateBuilder[T]
- func (b *CreateBuilder[T]) SetNillableSensitive(column string, value any) *CreateBuilder[T]
- func (b *CreateBuilder[T]) SetSensitive(column string, value any) *CreateBuilder[T]
- type CursorPage
- type DeleteBuilder
- type DeleteOneBuilder
- type Driver
- type EagerContext
- type EagerOption
- type Edge
- type EnumCol
- func (c EnumCol) As(alias string) SelectExpr
- func (c EnumCol) Asc() OrderTerm[T]
- func (c EnumCol) Desc() OrderTerm[T]
- func (c EnumCol[T, E]) Eq(v E) Pred[T]
- func (c EnumCol) Expr() MutationExpr
- func (c EnumCol[T, E]) In(v ...E) Pred[T]
- func (c EnumCol) IsNull() Pred[T]
- func (c EnumCol[T, E]) NEq(v E) Pred[T]
- func (c EnumCol[T, E]) NotIn(v ...E) Pred[T]
- func (c EnumCol) NotNull() Pred[T]
- func (c EnumCol) Ref() ColumnRef
- type ErrUnsupported
- type FKCol
- func (c FKCol) As(alias string) SelectExpr
- func (c FKCol) Asc() OrderTerm[T]
- func (c FKCol) Desc() OrderTerm[T]
- func (c FKCol[T, R, K]) Eq(v K) Pred[T]
- func (c FKCol) Expr() MutationExpr
- func (c FKCol[T, R, K]) In(v ...K) Pred[T]
- func (c FKCol) IsNull() Pred[T]
- func (c FKCol[T, R, K]) NEq(v K) Pred[T]
- func (c FKCol[T, R, K]) NotIn(v ...K) Pred[T]
- func (c FKCol) NotNull() Pred[T]
- func (c FKCol) Ref() ColumnRef
- type IsolationLevel
- type JSONCol
- func (c JSONCol) As(alias string) SelectExpr
- func (c JSONCol) Asc() OrderTerm[T]
- func (c JSONCol[T, V]) ContainedBy(v V) Pred[T]
- func (c JSONCol[T, V]) Contains(v V) Pred[T]
- func (c JSONCol) Desc() OrderTerm[T]
- func (c JSONCol[T, V]) Eq(v V) Pred[T]
- func (c JSONCol) Expr() MutationExpr
- func (c JSONCol[T, V]) HasKey(v string) Pred[T]
- func (c JSONCol) IsNull() Pred[T]
- func (c JSONCol) NotNull() Pred[T]
- func (c JSONCol[T, V]) PathEq(path []string, v V) Pred[T]
- func (c JSONCol) Ref() ColumnRef
- type JoinKind
- type LoadedMany
- type LoadedOne
- type LockMode
- type MutationBatch
- type MutationExpr
- func Add(left, right MutationExpr) MutationExpr
- func ArrayAppend(array, value MutationExpr) MutationExpr
- func Coalesce(exprs ...MutationExpr) MutationExpr
- func ColumnExpression(expr SelectExpr) MutationExpr
- func Div(left, right MutationExpr) MutationExpr
- func Excluded(column string) MutationExpr
- func ExprColumn(table, column string) MutationExpr
- func ExprSensitiveValue[T any](value T) MutationExpr
- func ExprValue[T any](value T) MutationExpr
- func JSONMerge(left, right MutationExpr) MutationExpr
- func JSONPath(value MutationExpr, path ...string) MutationExpr
- func Mul(left, right MutationExpr) MutationExpr
- func Sub(left, right MutationExpr) MutationExpr
- func VersionIncrement(column string) MutationExpr
- type MutationOption
- func WithMutationBatchSize(size int) MutationOption
- func WithMutationConstraintLookup(lookup dialect.ConstraintLookup) MutationOption
- func WithMutationEntity(entity string) MutationOption
- func WithMutationObserver(observer QueryObserver) MutationOption
- func WithMutationParameterLimit(limit int) MutationOption
- func WithMutationStrictScan(strict bool) MutationOption
- type NamedAnnotation
- type NamedQueryOptions
- type NumCol
- func (c NumCol) As(alias string) SelectExpr
- func (c NumCol) Asc() OrderTerm[T]
- func (c NumCol[T, N]) Between(lo, hi N) Pred[T]
- func (c NumCol) Desc() OrderTerm[T]
- func (c NumCol[T, N]) Eq(v N) Pred[T]
- func (c NumCol) Expr() MutationExpr
- func (c NumCol[T, N]) Gt(v N) Pred[T]
- func (c NumCol[T, N]) Gte(v N) Pred[T]
- func (c NumCol[T, N]) In(v ...N) Pred[T]
- func (c NumCol) IsNull() Pred[T]
- func (c NumCol[T, N]) Lt(v N) Pred[T]
- func (c NumCol[T, N]) Lte(v N) Pred[T]
- func (c NumCol[T, N]) NEq(v N) Pred[T]
- func (c NumCol[T, N]) NotIn(v ...N) Pred[T]
- func (c NumCol) NotNull() Pred[T]
- func (c NumCol) Ref() ColumnRef
- type OffsetPage
- type Operation
- type Option
- type OrderTerm
- type Page
- type ParamSpec
- type Pred
- func And[T any](preds ...Pred[T]) Pred[T]
- func CompareColumns[T any](left, right ColumnRef) Pred[T]
- func EdgePredicate[S any, R any](sourceTable, sourceColumn, targetTable, targetColumn, joinTable, ... string, ...) Pred[S]
- func Exists[T, R any](s Subquery[R]) Pred[T]
- func InSubquery[T, R any](column ownedSelectExpr[T], s Subquery[R]) Pred[T]
- func NewPred[T any](render func(*dialect.Writer, dialect.Dialect) error) Pred[T]
- func Not[T any](pred Pred[T]) Pred[T]
- func NotExists[T, R any](s Subquery[R]) Pred[T]
- func Or[T any](preds ...Pred[T]) Pred[T]
- func RawPred[T any](query string, args ...any) Pred[T]
- type Projection
- type ProjectionSlot
- type Query
- func Join[S, R any](q *Query[S], edge Edge[S, R], kind JoinKind) *Query[S]
- func JoinInner[S, R any](q *Query[S], edge Edge[S, R]) *Query[S]
- func JoinLeft[S, R any](q *Query[S], edge Edge[S, R]) *Query[S]
- func JoinOn[S, R any](q *Query[S], edge Edge[S, R], kind JoinKind, predicate Pred[R]) *Query[S]
- func JoinRight[S, R any](q *Query[S], edge Edge[S, R]) *Query[S]
- func NewQuery[T any](drv Driver, table string, options ...QueryOption) *Query[T]
- func (q *Query[T]) All(ctx context.Context) ([]T, error)
- func (q *Query[T]) Count(ctx context.Context) (int64, error)
- func (q *Query[T]) Distinct() *Query[T]
- func (q *Query[T]) DistinctOn(exprs ...SelectExpr) *Query[T]
- func (q *Query[T]) EagerManyToManySQL(joinTable, sourceJoinColumn, targetJoinColumn, targetPrimaryKey string, ...) (string, []any, error)
- func (q *Query[T]) EagerQuery() (*Query[T], int)
- func (q *Query[T]) Exist(ctx context.Context) (bool, error)
- func (q *Query[T]) First(ctx context.Context) (*T, error)
- func (q *Query[T]) ForShare() *Query[T]
- func (q *Query[T]) ForUpdate() *Query[T]
- func (q *Query[T]) GroupBy(exprs ...SelectExpr) *Query[T]
- func (q *Query[T]) Having(preds ...Pred[T]) *Query[T]
- func (q *Query[T]) IDs(ctx context.Context) ([]string, error)
- func (q *Query[T]) Iterate(ctx context.Context, fn func(T) error) error
- func (q *Query[T]) Limit(limit int) *Query[T]
- func (q *Query[T]) Nowait() *Query[T]
- func (q *Query[T]) Offset(offset int) *Query[T]
- func (q *Query[T]) One(ctx context.Context) (*T, error)
- func (q *Query[T]) OnlyDeleted() *Query[T]
- func (q *Query[T]) Order(terms ...OrderTerm[T]) *Query[T]
- func (q *Query[T]) Paginate(ctx context.Context, request any) (Page[T], error)
- func (q *Query[T]) SQL() (string, []any, error)
- func (q *Query[T]) Select(exprs ...SelectExpr) *Query[T]
- func (q *Query[T]) SkipLocked() *Query[T]
- func (q *Query[T]) Subquery() Subquery[T]
- func (q *Query[T]) Where(preds ...Pred[T]) *Query[T]
- func (q *Query[T]) With(options ...EagerOption[T]) *Query[T]
- func (q *Query[T]) WithCTE(ctes ...CTE) *Query[T]
- func (q *Query[T]) WithDeleted() *Query[T]
- type QueryInfo
- type QueryObserver
- type QueryOption
- func WithQueryConstraintLookup(lookup dialect.ConstraintLookup) QueryOption
- func WithQueryCursorKey(key []byte) QueryOption
- func WithQueryEntity(entity string) QueryOption
- func WithQueryIDColumn(column string) QueryOption
- func WithQueryMaxPageSize(size int) QueryOption
- func WithQueryObserver(observer QueryObserver) QueryOption
- func WithQuerySoftDelete(column string) QueryOption
- func WithQueryStrictScan(strict bool) QueryOption
- type QuerySpec
- type RawExecQuery
- type RawQuery
- func (q *RawQuery[T]) All(ctx context.Context) ([]T, error)
- func (q *RawQuery[T]) First(ctx context.Context) (*T, error)
- func (q *RawQuery[T]) Iterate(ctx context.Context, fn func(T) error) error
- func (q *RawQuery[T]) Lax() *RawQuery[T]
- func (q *RawQuery[T]) One(ctx context.Context) (*T, error)
- func (q *RawQuery[T]) SQL() (string, []any, error)
- type ReadOnlyDriver
- type RelationMutation
- func (m *RelationMutation) Attach(ctx context.Context, targets ...any) (int64, error)
- func (m *RelationMutation) AttachRows(ctx context.Context, rows ...RelationRow) (int64, error)
- func (m *RelationMutation) Detach(ctx context.Context, targets ...any) (int64, error)
- func (m *RelationMutation) Replace(ctx context.Context, targets ...any) (int64, error)
- type RelationRow
- type RestoreBuilder
- type Result
- type ResultFieldSpec
- type ResultMode
- type ResultSpec
- type RetryOptions
- type Rows
- type SavepointDriver
- type SavepointOptions
- type Scope
- type SelectExpr
- func As(expr SelectExpr, alias string) SelectExpr
- func Avg(column SelectExpr) SelectExpr
- func Count(column SelectExpr) SelectExpr
- func CountAll() SelectExpr
- func Max(column SelectExpr) SelectExpr
- func Min(column SelectExpr) SelectExpr
- func NestedProjection(prefix string, exprs ...SelectExpr) []SelectExpr
- func OuterColumn(ref ColumnRef) SelectExpr
- func Scalar[T any](s Subquery[T]) SelectExpr
- func Slot(expr SelectExpr, alias string, nullable ...bool) SelectExpr
- func Sum(column SelectExpr) SelectExpr
- type Selectable
- type Shape
- type Subquery
- type TextCol
- func (c TextCol) As(alias string) SelectExpr
- func (c TextCol) Asc() OrderTerm[T]
- func (c TextCol[T]) Contains(v string) Pred[T]
- func (c TextCol[T]) ContainsFold(v string) Pred[T]
- func (c TextCol) Desc() OrderTerm[T]
- func (c TextCol[T]) Eq(v string) Pred[T]
- func (c TextCol) Expr() MutationExpr
- func (c TextCol[T]) HasPrefix(v string) Pred[T]
- func (c TextCol[T]) HasSuffix(v string) Pred[T]
- func (c TextCol[T]) ILike(v string) Pred[T]
- func (c TextCol[T]) In(v ...string) Pred[T]
- func (c TextCol) IsNull() Pred[T]
- func (c TextCol[T]) Like(v string) Pred[T]
- func (c TextCol[T]) NEq(v string) Pred[T]
- func (c TextCol[T]) NotIn(v ...string) Pred[T]
- func (c TextCol) NotNull() Pred[T]
- func (c TextCol) Ref() ColumnRef
- type TimeCol
- func (c TimeCol[T]) After(v time.Time) Pred[T]
- func (c TimeCol) As(alias string) SelectExpr
- func (c TimeCol) Asc() OrderTerm[T]
- func (c TimeCol[T]) Before(v time.Time) Pred[T]
- func (c TimeCol[T]) Between(lo, hi time.Time) Pred[T]
- func (c TimeCol) Desc() OrderTerm[T]
- func (c TimeCol[T]) Eq(v time.Time) Pred[T]
- func (c TimeCol) Expr() MutationExpr
- func (c TimeCol) IsNull() Pred[T]
- func (c TimeCol) NotNull() Pred[T]
- func (c TimeCol) Ref() ColumnRef
- type TxDriver
- type TxOptions
- type TypeRef
- type UpdateBuilder
- func (b *UpdateBuilder[T]) Clear(column string) *UpdateBuilder[T]
- func (b *UpdateBuilder[T]) ClearSensitive(column string) *UpdateBuilder[T]
- func (b *UpdateBuilder[T]) Exec(ctx context.Context) (int64, error)
- func (b *UpdateBuilder[T]) Returning(exprs ...SelectExpr) *UpdateBuilder[T]
- func (b *UpdateBuilder[T]) SQL() (string, []any, error)
- func (b *UpdateBuilder[T]) Save(ctx context.Context) (*T, error)
- func (b *UpdateBuilder[T]) Set(column string, value any) *UpdateBuilder[T]
- func (b *UpdateBuilder[T]) SetExpr(column string, expression MutationExpr) *UpdateBuilder[T]
- func (b *UpdateBuilder[T]) SetNillable(column string, value any) *UpdateBuilder[T]
- func (b *UpdateBuilder[T]) SetNillableSensitive(column string, value any) *UpdateBuilder[T]
- func (b *UpdateBuilder[T]) SetSensitive(column string, value any) *UpdateBuilder[T]
- func (b *UpdateBuilder[T]) Where(preds ...Pred[T]) *UpdateBuilder[T]
- func (b *UpdateBuilder[T]) WithOptimisticLock(column string, expected any) *UpdateBuilder[T]
- type UpsertBuilder
- func (b *UpsertBuilder[T]) DoNothing() *UpsertBuilder[T]
- func (b *UpsertBuilder[T]) Exec(ctx context.Context) (int64, error)
- func (b *UpsertBuilder[T]) OnColumns(columns ...ColumnRef) *UpsertBuilder[T]
- func (b *UpsertBuilder[T]) OnConflict(target ConflictTarget) *UpsertBuilder[T]
- func (b *UpsertBuilder[T]) OnConstraint(name string) *UpsertBuilder[T]
- func (b *UpsertBuilder[T]) Plan() UpsertPlan
- func (b *UpsertBuilder[T]) Returning(exprs ...SelectExpr) *UpsertBuilder[T]
- func (b *UpsertBuilder[T]) SQL() (string, []any, error)
- func (b *UpsertBuilder[T]) Save(ctx context.Context) (*T, error)
- func (b *UpsertBuilder[T]) Set(column string, value any) *UpsertBuilder[T]
- func (b *UpsertBuilder[T]) SetExpr(column string, expression MutationExpr) *UpsertBuilder[T]
- func (b *UpsertBuilder[T]) SetSensitive(column string, value any) *UpsertBuilder[T]
- func (b *UpsertBuilder[T]) Update(assignments ...Assignment) *UpsertBuilder[T]
- func (b *UpsertBuilder[T]) Where(pred any) *UpsertBuilder[T]
- type UpsertPlan
- type ValueCol
- func (c ValueCol) As(alias string) SelectExpr
- func (c ValueCol) Asc() OrderTerm[T]
- func (c ValueCol) Desc() OrderTerm[T]
- func (c ValueCol[T, V]) Eq(v V) Pred[T]
- func (c ValueCol) Expr() MutationExpr
- func (c ValueCol[T, V]) In(v ...V) Pred[T]
- func (c ValueCol) IsNull() Pred[T]
- func (c ValueCol[T, V]) NEq(v V) Pred[T]
- func (c ValueCol[T, V]) NotIn(v ...V) Pred[T]
- func (c ValueCol) NotNull() Pred[T]
- func (c ValueCol) Ref() ColumnRef
Constants ¶
const ( ConstraintUnique = dialect.ConstraintUnique ConstraintForeignKey = dialect.ConstraintForeignKey ConstraintCheck = dialect.ConstraintCheck ConstraintNotNull = dialect.ConstraintNotNull )
Re-export constraint kind constants.
Variables ¶
var ( // ErrNotFound is returned when a query expects a row but none is found. ErrNotFound = errors.New("funq: row not found") // ErrTooManyRows is returned when a query expects at most one row but finds more. ErrTooManyRows = errors.New("funq: too many rows returned") // Binding errors are re-exported for callers that do not need to import the // neutral bind package just to classify generated-binder failures. ErrUnknownField = bind.ErrUnknownField ErrBadOperator = bind.ErrBadOperator ErrBadValue = bind.ErrBadValue // ErrConflict is returned when optimistic locking observes no matching // version, or when an explicitly conflict-sensitive mutation cannot // determine a winner. ErrConflict = errors.New("funq: optimistic locking conflict") // ErrTransactionRequired is returned before I/O for operations whose SQL // semantics require a transaction, such as row locks and relation changes. ErrTransactionRequired = errors.New("funq: transaction required") // ErrReadOnly is returned when a write or lock-bearing operation is sent to // a read-only transaction or replica. ErrReadOnly = errors.New("funq: read-only driver") )
var ErrInvalidCursor = errors.New("funq: invalid cursor")
ErrInvalidCursor reports a malformed, stale, or tampered cursor.
Functions ¶
func ContextConstraintLookup ¶
func ContextConstraintLookup(ctx context.Context) (dialect.ConstraintLookup, bool)
ContextConstraintLookup retrieves the ConstraintLookup from context if present.
func ContextSensitivePositions ¶
ContextSensitivePositions retrieves the sensitive argument positions from context.
func IsRetryable ¶
IsRetryable reports whether err is a normalized serialization or deadlock failure. Conflict errors are intentionally not retryable.
func NamedExec ¶
func NamedExec(ctx context.Context, drv Driver, sql string, args []any, options NamedQueryOptions) (int64, error)
NamedExec executes command SQL and returns its affected-row count.
func NamedFirst ¶
func NamedFirst[T any](ctx context.Context, drv Driver, sql string, args []any, options NamedQueryOptions) (*T, error)
NamedFirst executes a named SQL operation and returns its first row.
func NamedIterate ¶
func NamedIterate[T any](ctx context.Context, drv Driver, sql string, args []any, fn func(T) error, options NamedQueryOptions) error
NamedIterate streams a named SQL result through the standard scanner.
func NamedOne ¶
func NamedOne[T any](ctx context.Context, drv Driver, sql string, args []any, options NamedQueryOptions) (*T, error)
NamedOne executes a named SQL operation and requires exactly one row.
func NamedQuery ¶
func NamedQuery[T any](ctx context.Context, drv Driver, sql string, args []any, options NamedQueryOptions) ([]T, error)
NamedQuery executes a named SQL operation and scans all rows using the standard scanner and observer path.
func Observe ¶
Observe checks if there is a QueryObserver in the context, and if so, triggers it after redacting sensitive arguments.
func RedactArgs ¶
RedactArgs returns a copy of args with sensitive positions redacted.
func RunInSavepoint ¶
func RunInSavepoint(ctx context.Context, tx TxDriver, fn func(TxDriver) error, options ...SavepointOptions) (err error)
RunInSavepoint executes fn inside a deterministic savepoint. Callback errors roll back to the savepoint and release it; successful callbacks only release it. Drivers without savepoints fail before fn is invoked.
func RunInTx ¶
RunInTx runs a callback function within a transaction. If driver is already a TxDriver (i.e. we are already in an active transaction), it invokes the callback immediately without starting a nested transaction. Otherwise, it starts a new transaction, runs the callback, and commits if the callback returns nil, or rolls back if the callback returns an error or panics.
If the rollback fails, the error is joined with the callback error or reported to the observer in case of a panic.
func RunInTxRetry ¶
func RunInTxRetry(ctx context.Context, d Driver, txOptions TxOptions, retry RetryOptions, fn func(TxDriver) error) error
RunInTxRetry retries a complete transaction only for normalized serialization/deadlock errors. Each attempt receives a fresh transaction.
func RunInTxWithRetry ¶
func RunInTxWithRetry(ctx context.Context, d Driver, txOptions TxOptions, retry RetryOptions, fn func(TxDriver) error) error
RunInTxWithRetry is a descriptive alias for RunInTxRetry.
func Scan ¶
Scan executes a typed query and scans its projection into destination T. The query's source entity and destination type are intentionally separate; this is what permits aggregate and arbitrary projection results.
func WithConstraintLookup ¶
WithConstraintLookup returns a context holding the given ConstraintLookup.
func WithContextObserver ¶
func WithContextObserver(ctx context.Context, obs QueryObserver) context.Context
WithContextObserver returns a context holding the given QueryObserver.
func WithNamedQueryMetadata ¶
func WithNamedQueryMetadata(ctx context.Context, entity string, op Operation, readOnly bool, expectedColumns []string) context.Context
WithNamedQueryMetadata records the complete metadata contract for a named SQL operation before it reaches the driver and observer.
func WithQueryMetadata ¶
WithQueryMetadata returns a context holding query metadata.
Types ¶
type Annotation ¶
type Annotation struct {
Namespace string `json:"namespace"`
Payload json.RawMessage `json:"payload,omitempty"`
}
Annotation is opaque metadata attached to a named SQL declaration. Generators preserve annotations but do not interpret them.
type ArrayCol ¶
ArrayCol is a typed array column handle.
func NewArrayCol ¶
func (ArrayCol) As ¶
func (c ArrayCol) As(alias string) SelectExpr
As gives a column a SELECT alias.
func (ArrayCol) Expr ¶
func (c ArrayCol) Expr() MutationExpr
Expr exposes the column as a typed mutation expression. All generated column handles inherit this method through columnBase.
type Assignment ¶
type Assignment struct {
Column string
Value any
Expression MutationExpr
Sensitive bool
}
Assignment is a declaration-order mutation assignment.
func Assign ¶
func Assign(column string, value any) Assignment
func AssignExpr ¶
func AssignExpr(column string, expression MutationExpr) Assignment
func AssignSensitive ¶
func AssignSensitive(column string, value any) Assignment
type BoolCol ¶
type BoolCol[T any] struct { // contains filtered or unexported fields }
BoolCol is a typed boolean column handle.
func (BoolCol) Expr ¶
func (c BoolCol) Expr() MutationExpr
Expr exposes the column as a typed mutation expression. All generated column handles inherit this method through columnBase.
type BulkInsertBuilder ¶
type BulkInsertBuilder[T any] struct { // contains filtered or unexported fields }
func NewBulkInsert ¶
func NewBulkInsert[T any](drv Driver, table string, options ...MutationOption) *BulkInsertBuilder[T]
func (*BulkInsertBuilder[T]) Add ¶
func (b *BulkInsertBuilder[T]) Add(row BulkRow) *BulkInsertBuilder[T]
func (*BulkInsertBuilder[T]) AddRow ¶
func (b *BulkInsertBuilder[T]) AddRow(assignments ...Assignment) *BulkInsertBuilder[T]
func (*BulkInsertBuilder[T]) BatchSize ¶
func (b *BulkInsertBuilder[T]) BatchSize(size int) *BulkInsertBuilder[T]
func (*BulkInsertBuilder[T]) Batches ¶
func (b *BulkInsertBuilder[T]) Batches() ([]MutationBatch, error)
func (*BulkInsertBuilder[T]) Exec ¶
func (b *BulkInsertBuilder[T]) Exec(ctx context.Context) (int64, error)
func (*BulkInsertBuilder[T]) ParameterLimit ¶
func (b *BulkInsertBuilder[T]) ParameterLimit(limit int) *BulkInsertBuilder[T]
type BulkRow ¶
type BulkRow struct{ Assignments []Assignment }
BulkRow holds one insert row. All rows in a batch must have the same column shape; rows with other shapes are grouped separately.
func NewBulkRow ¶
func NewBulkRow(assignments ...Assignment) BulkRow
type CTE ¶
type CTE struct {
Name string
Columns []string
Body Selectable
Recursive bool
RecursiveBody Selectable
}
CTE is a declared common-table expression.
func NewRecursiveCTE ¶
func NewRecursiveCTE(name string, columns []string, anchor, recursive Selectable) CTE
type ColumnRef ¶
ColumnRef is a typed source-column identity used by joins and correlations. It is an identity, not a raw SQL fragment, and is always quoted on render.
func NewColumnRef ¶
NewColumnRef creates a column identity for composition helpers.
type Config ¶
type Config struct {
Observer QueryObserver
MaxPageSize int
CursorKey []byte
StrictScan bool
}
Config holds runtime configuration options for the client.
type ConflictTarget ¶
ConflictTarget identifies a unique conflict target. Exactly one of Constraint or Columns must be supplied. Predicate is accepted as a typed Pred[T] value and is checked against the upsert entity during rendering.
type ConstraintError ¶
type ConstraintError = dialect.ConstraintError
ConstraintError represents a database constraint violation.
type ConstraintKind ¶
type ConstraintKind = dialect.ConstraintKind
ConstraintKind identifies the database constraint type that was violated.
type CopyBuilder ¶
type CopyBuilder struct {
// contains filtered or unexported fields
}
CopyBuilder is an opt-in COPY mutation. It requires a CopyDriver and never silently falls back to INSERT.
func NewCopy ¶
func NewCopy(drv Driver, table string, columns []string, source CopySource, options ...MutationOption) *CopyBuilder
type CopyDriver ¶
type CopyDriver interface {
Driver
CopyFrom(ctx context.Context, table string, columns []string, source CopySource) (int64, error)
}
CopyDriver is an optional bulk-write interface. COPY is intentionally not part of Driver because its conflict, returning, and trigger semantics are different from regular INSERT.
type CopySource ¶
CopySource is the neutral row stream consumed by a COPY-capable driver. Values must be returned in the same order as the requested COPY columns.
type CreateBuilder ¶
type CreateBuilder[T any] struct { // contains filtered or unexported fields }
CreateBuilder is an explicit INSERT builder. Generated setters are thin wrappers around Set and therefore retain compile-time field/value typing in the generated package.
func NewCreate ¶
func NewCreate[T any](drv Driver, table string, options ...MutationOption) *CreateBuilder[T]
func NewCreateBuilder ¶
func NewCreateBuilder[T any](drv Driver, table string, options ...MutationOption) *CreateBuilder[T]
NewCreateBuilder is an explicit alias useful to generated code.
func (*CreateBuilder[T]) Clear ¶
func (b *CreateBuilder[T]) Clear(column string) *CreateBuilder[T]
func (*CreateBuilder[T]) ClearSensitive ¶
func (b *CreateBuilder[T]) ClearSensitive(column string) *CreateBuilder[T]
ClearSensitive clears a sensitive create field and keeps it redacted in observer notifications.
func (*CreateBuilder[T]) Require ¶
func (b *CreateBuilder[T]) Require(columns ...string) *CreateBuilder[T]
Require marks fields that must be present and non-nil before SQL rendering.
func (*CreateBuilder[T]) Returning ¶
func (b *CreateBuilder[T]) Returning(exprs ...SelectExpr) *CreateBuilder[T]
Returning selects a typed projection for a create mutation.
func (*CreateBuilder[T]) Set ¶
func (b *CreateBuilder[T]) Set(column string, value any) *CreateBuilder[T]
func (*CreateBuilder[T]) SetExpr ¶
func (b *CreateBuilder[T]) SetExpr(column string, expression MutationExpr) *CreateBuilder[T]
SetExpr assigns an expression without reading the current row first.
func (*CreateBuilder[T]) SetNillable ¶
func (b *CreateBuilder[T]) SetNillable(column string, value any) *CreateBuilder[T]
func (*CreateBuilder[T]) SetNillableSensitive ¶
func (b *CreateBuilder[T]) SetNillableSensitive(column string, value any) *CreateBuilder[T]
SetNillableSensitive is SetNillable with observer redaction enabled.
func (*CreateBuilder[T]) SetSensitive ¶
func (b *CreateBuilder[T]) SetSensitive(column string, value any) *CreateBuilder[T]
SetSensitive marks a create argument as sensitive for observer redaction.
type CursorPage ¶
CursorPage requests a stable keyset page. After and Before are mutually exclusive opaque cursors.
type DeleteBuilder ¶
type DeleteBuilder[T any] struct { // contains filtered or unexported fields }
DeleteBuilder is an explicit DELETE builder. DeleteOne is represented by the same builder with single=true and reports ErrNotFound for zero rows.
func NewDelete ¶
func NewDelete[T any](drv Driver, table string, options ...MutationOption) *DeleteBuilder[T]
func (*DeleteBuilder[T]) Where ¶
func (b *DeleteBuilder[T]) Where(preds ...Pred[T]) *DeleteBuilder[T]
type DeleteOneBuilder ¶
type DeleteOneBuilder[T any] struct { // contains filtered or unexported fields }
DeleteOneBuilder is the single-row delete variant. Its Exec method returns ErrNotFound when the key does not exist.
func NewDeleteOne ¶
func NewDeleteOne[T any](drv Driver, table, idColumn string, id any, options ...MutationOption) *DeleteOneBuilder[T]
func (*DeleteOneBuilder[T]) Where ¶
func (b *DeleteOneBuilder[T]) Where(preds ...Pred[T]) *DeleteOneBuilder[T]
type Driver ¶
type Driver interface {
Query(ctx context.Context, sql string, args ...any) (Rows, error)
Exec(ctx context.Context, sql string, args ...any) (Result, error)
Begin(ctx context.Context, opts TxOptions) (TxDriver, error)
Dialect() dialect.Dialect
}
Driver is the core abstraction for database query and execution.
type EagerContext ¶
EagerContext contains the immutable runtime settings needed by a generated eager loader. Loaders receive the same driver and scan policy as the base query, so eager loading also works inside caller-owned transactions.
type EagerOption ¶
type EagerOption[T any] struct { // contains filtered or unexported fields }
EagerOption describes one generated relationship loader.
func NewEagerOption ¶
func NewEagerOption[T any](name string, load func(context.Context, EagerContext, []T) error) EagerOption[T]
NewEagerOption creates an eager-loading option for a generated edge.
type Edge ¶
type Edge[S, R any] struct { Name string SourceTable string TargetTable string SourceColumns []string TargetColumns []string TargetAlias string SourceEntity string TargetEntity string Nullable bool }
Edge is a generated-style declared relationship descriptor. Only an Edge can be passed to Join, so composition cannot invent a column pair from SQL strings at the call site.
type EnumCol ¶
EnumCol is a typed string-backed enum column handle.
func NewEnumCol ¶
func (EnumCol) Expr ¶
func (c EnumCol) Expr() MutationExpr
Expr exposes the column as a typed mutation expression. All generated column handles inherit this method through columnBase.
type ErrUnsupported ¶
type ErrUnsupported struct {
Dialect string
Capability dialect.Capability
Operation string
}
ErrUnsupported represents an error when a dialect does not support a specific capability.
func (*ErrUnsupported) Error ¶
func (e *ErrUnsupported) Error() string
type FKCol ¶
FKCol is a typed foreign-key column handle. R and K document the related entity and key type and make accidental cross-entity predicates impossible.
func (FKCol) Expr ¶
func (c FKCol) Expr() MutationExpr
Expr exposes the column as a typed mutation expression. All generated column handles inherit this method through columnBase.
type IsolationLevel ¶
type IsolationLevel string
IsolationLevel defines the SQL transaction isolation level.
const ( IsolationDefault IsolationLevel = "" IsolationReadUncommitted IsolationLevel = "read uncommitted" IsolationReadCommitted IsolationLevel = "read committed" IsolationRepeatableRead IsolationLevel = "repeatable read" IsolationSerializable IsolationLevel = "serializable" )
Standard SQL transaction isolation levels.
type JSONCol ¶
JSONCol is a typed JSON column handle.
func NewJSONCol ¶
func (JSONCol[T, V]) ContainedBy ¶
func (JSONCol) Expr ¶
func (c JSONCol) Expr() MutationExpr
Expr exposes the column as a typed mutation expression. All generated column handles inherit this method through columnBase.
type LoadedMany ¶
type LoadedMany[T any] struct { // contains filtered or unexported fields }
LoadedMany stores the state of an optionally eager-loaded collection edge.
func (LoadedMany[T]) Get ¶
func (l LoadedMany[T]) Get() ([]T, bool)
Get returns a copy of the loaded values and whether the edge was loaded.
func (*LoadedMany[T]) Set ¶
func (l *LoadedMany[T]) Set(values []T)
Set marks the edge as loaded. The supplied slice is copied.
type LoadedOne ¶
type LoadedOne[T any] struct { // contains filtered or unexported fields }
LoadedOne stores the state of an optionally eager-loaded singular edge. A zero value means that the edge has not been requested or loaded.
type LockMode ¶
type LockMode string
LockMode is an explicit row-lock clause. Lock-bearing queries are accepted only by transaction-bound drivers at execution time.
type MutationBatch ¶
MutationBatch is one deterministic SQL batch emitted by BulkInsertBuilder.
type MutationExpr ¶
type MutationExpr struct {
// contains filtered or unexported fields
}
MutationExpr is a typed mutation expression. Values are bound arguments; column and EXCLUDED references are quoted generated handles.
func Add ¶
func Add(left, right MutationExpr) MutationExpr
func ArrayAppend ¶
func ArrayAppend(array, value MutationExpr) MutationExpr
ArrayAppend emits array_append(array, value).
func Coalesce ¶
func Coalesce(exprs ...MutationExpr) MutationExpr
Coalesce emits COALESCE with deterministic expression order.
func ColumnExpression ¶
func ColumnExpression(expr SelectExpr) MutationExpr
ColumnExpression creates a generated column reference for an expression.
func Div ¶
func Div(left, right MutationExpr) MutationExpr
func Excluded ¶
func Excluded(column string) MutationExpr
Excluded references the PostgreSQL upsert EXCLUDED pseudo-table.
func ExprColumn ¶
func ExprColumn(table, column string) MutationExpr
ExprColumn creates a generated column reference without requiring a query column handle. Generated code generally uses column.Expr() instead.
func ExprSensitiveValue ¶
func ExprSensitiveValue[T any](value T) MutationExpr
ExprSensitiveValue creates a redacted bound mutation value.
func ExprValue ¶
func ExprValue[T any](value T) MutationExpr
ExprValue creates a bound mutation value.
func JSONMerge ¶
func JSONMerge(left, right MutationExpr) MutationExpr
JSONMerge emits the PostgreSQL JSONB merge operator.
func JSONPath ¶
func JSONPath(value MutationExpr, path ...string) MutationExpr
JSONPath emits a PostgreSQL JSONB path extraction expression.
func Mul ¶
func Mul(left, right MutationExpr) MutationExpr
func Sub ¶
func Sub(left, right MutationExpr) MutationExpr
func VersionIncrement ¶
func VersionIncrement(column string) MutationExpr
VersionIncrement emits a single-statement version increment.
type MutationOption ¶
type MutationOption func(*mutationConfig)
MutationOption configures a create, update, or delete builder.
func WithMutationBatchSize ¶
func WithMutationBatchSize(size int) MutationOption
WithMutationBatchSize configures the maximum number of rows in a bulk mutation batch.
func WithMutationConstraintLookup ¶
func WithMutationConstraintLookup(lookup dialect.ConstraintLookup) MutationOption
WithMutationConstraintLookup supplies generated constraint metadata.
func WithMutationEntity ¶
func WithMutationEntity(entity string) MutationOption
func WithMutationObserver ¶
func WithMutationObserver(observer QueryObserver) MutationOption
WithMutationObserver attaches a passive observer to generated mutations.
func WithMutationParameterLimit ¶
func WithMutationParameterLimit(limit int) MutationOption
WithMutationParameterLimit configures the maximum bind parameters per bulk mutation batch.
func WithMutationStrictScan ¶
func WithMutationStrictScan(strict bool) MutationOption
type NamedAnnotation ¶
type NamedAnnotation = Annotation
NamedAnnotation is retained as a descriptive alias for Annotation.
type NamedQueryOptions ¶
type NamedQueryOptions struct {
Name string
Entity string
ReadOnly bool
SensitivePositions []int
ExpectedColumns []string
ExpectedOrdinals []int
ScanColumns []string
Partial bool
Strict bool
ConstraintLookup dialect.ConstraintLookup
}
NamedQueryOptions carries generated metadata and the explicit result contract for a named SQL operation.
type NumCol ¶
NumCol is a typed numeric column handle.
func (NumCol) Expr ¶
func (c NumCol) Expr() MutationExpr
Expr exposes the column as a typed mutation expression. All generated column handles inherit this method through columnBase.
type OffsetPage ¶
OffsetPage requests a one-based page. Size is defaulted and clamped by the query's configured maximum page size.
type Option ¶
type Option func(*Config)
Option applies a configuration option.
func Lax ¶
func Lax() Option
Lax is an option helper to disable strict scanning (equivalent to WithStrictScan(false)).
func WithCursorKey ¶
WithCursorKey configures the secret key used for HMAC signing of keyset cursors.
func WithMaxPageSize ¶
WithMaxPageSize sets the maximum limit size allowed for pagination.
func WithObserver ¶
func WithObserver(observer QueryObserver) Option
WithObserver registers a query observer.
func WithStrictScan ¶
WithStrictScan enables or disables strict schema mapping during row scanning.
type OrderTerm ¶
type OrderTerm[T any] struct { // contains filtered or unexported fields }
OrderTerm describes an ordered entity column. Order terms are immutable; NullsFirst and NullsLast return modified copies.
func (OrderTerm[T]) NullsFirst ¶
type Page ¶
Page is returned by both pagination modes. Offset pages populate Number, Size, and Total; cursor pages populate Next and Previous.
type ParamSpec ¶
ParamSpec describes one named SQL argument. Arguments are bound in slice order, independently of the order in which placeholders appear in SQL.
type Pred ¶
type Pred[T any] struct { // contains filtered or unexported fields }
Pred represents a typed query predicate for entity T. It is a value rather than an interface so Go can infer T in expressions such as Not(postq.ID.Eq (id)) and Or(postq.Title.Eq(a), postq.Title.Eq(b)).
func CompareColumns ¶
CompareColumns compares two typed column identities. It is useful for the equality predicate that connects an inner query to an outer scope.
func EdgePredicate ¶
func EdgePredicate[S any, R any](sourceTable, sourceColumn, targetTable, targetColumn, joinTable, sourceJoinColumn, targetJoinColumn string, predicates ...Pred[R]) Pred[S]
EdgePredicate renders a correlated EXISTS predicate for a declared edge. When joinTable is empty, sourceColumn and targetColumn are compared directly between sourceTable and targetTable. When it is present, the join table is traversed using sourceJoinColumn and targetJoinColumn.
func InSubquery ¶
type Projection ¶
type Projection []SelectExpr
Projection is the returning projection in a mutation plan.
func NewProjection ¶
func NewProjection(exprs ...SelectExpr) Projection
type ProjectionSlot ¶
type ProjectionSlot struct {
Alias string
SourcePath string
Column string
GoType string
Nullable bool
}
ProjectionSlot is the scanner contract for one selected value.
type Query ¶
type Query[T any] struct { // contains filtered or unexported fields }
Query is an immutable, typed SELECT builder. Every builder method returns a copy, so a base query can safely be used to construct independent branches.
func JoinOn ¶
JoinOn adds a declared join and an additional typed predicate on its target entity. The edge predicate is rendered after the generated key predicate.
func NewQuery ¶
func NewQuery[T any](drv Driver, table string, options ...QueryOption) *Query[T]
NewQuery creates a typed query for table.
func (*Query[T]) Count ¶
Count returns the number of rows matching the filters. Ordering and paging are deliberately excluded from the count.
func (*Query[T]) DistinctOn ¶
func (q *Query[T]) DistinctOn(exprs ...SelectExpr) *Query[T]
DistinctOn marks the query as PostgreSQL-style SELECT DISTINCT ON.
func (*Query[T]) EagerManyToManySQL ¶
func (q *Query[T]) EagerManyToManySQL(joinTable, sourceJoinColumn, targetJoinColumn, targetPrimaryKey string, sourceIDs []any) (string, []any, error)
EagerManyToManySQL builds the single batched statement used for a many-to-many eager load. The result contains all target columns plus a private source-key column named _funq_source_id. Query filters and ordering are retained; pagination is intentionally removed by EagerQuery.
func (*Query[T]) EagerQuery ¶
EagerQuery returns a copy suitable for a batched edge query and its requested per-parent limit. Global offset and limit are removed; generated loaders enforce the limit independently for each parent.
func (*Query[T]) GroupBy ¶
func (q *Query[T]) GroupBy(exprs ...SelectExpr) *Query[T]
func (*Query[T]) Nowait ¶
Nowait makes the selected row lock fail immediately when a conflicting lock is held. It is valid only after ForUpdate or ForShare.
func (*Query[T]) One ¶
One expects exactly one row, returning ErrNotFound or ErrTooManyRows as appropriate.
func (*Query[T]) OnlyDeleted ¶
func (*Query[T]) Select ¶
func (q *Query[T]) Select(exprs ...SelectExpr) *Query[T]
func (*Query[T]) SkipLocked ¶
SkipLocked makes the selected row lock skip conflicting rows. It is valid only after ForUpdate or ForShare.
func (*Query[T]) With ¶
func (q *Query[T]) With(options ...EagerOption[T]) *Query[T]
With requests one or more explicit eager-load operations. Options are immutable and are executed only by a terminal operation.
func (*Query[T]) WithDeleted ¶
type QueryInfo ¶
type QueryInfo struct {
SQL string
Args []any
Duration time.Duration
Entity string
Operation Operation
ReadOnly bool
ExpectedColumns []string
Err error
}
QueryInfo contains diagnostic information about a completed query.
type QueryObserver ¶
QueryObserver defines the interface for passive post-query monitoring.
func ContextObserver ¶
func ContextObserver(ctx context.Context) (QueryObserver, bool)
ContextObserver retrieves the QueryObserver from context if present.
type QueryOption ¶
type QueryOption func(*queryConfig)
QueryOption configures a typed query created with NewQuery.
func WithQueryConstraintLookup ¶
func WithQueryConstraintLookup(lookup dialect.ConstraintLookup) QueryOption
WithQueryConstraintLookup supplies generated constraint metadata.
func WithQueryCursorKey ¶
func WithQueryCursorKey(key []byte) QueryOption
WithQueryCursorKey configures HMAC signing for keyset cursors.
func WithQueryEntity ¶
func WithQueryEntity(entity string) QueryOption
func WithQueryIDColumn ¶
func WithQueryIDColumn(column string) QueryOption
func WithQueryMaxPageSize ¶
func WithQueryMaxPageSize(size int) QueryOption
func WithQueryObserver ¶
func WithQueryObserver(observer QueryObserver) QueryOption
WithQueryObserver attaches a passive observer to generated query execution.
func WithQuerySoftDelete ¶
func WithQuerySoftDelete(column string) QueryOption
func WithQueryStrictScan ¶
func WithQueryStrictScan(strict bool) QueryOption
type QuerySpec ¶
type QuerySpec struct {
Name string
SQLFile string
Args []ParamSpec
Result ResultSpec
Interface string
ReadOnly bool
Annotations []NamedAnnotation
// GoName optionally overrides the generated method and type prefix. SQL
// operation identity remains Name.
GoName string `json:"goName,omitempty"`
}
QuerySpec declares one named SQL operation.
type RawExecQuery ¶
type RawExecQuery struct {
// contains filtered or unexported fields
}
RawExecQuery represents a raw SQL execution query.
func RawExec ¶
func RawExec(drv Driver, query string, args ...any) *RawExecQuery
RawExec creates a new raw SQL execution query (e.g. for mutations).
type RawQuery ¶
type RawQuery[T any] struct { // contains filtered or unexported fields }
RawQuery represents a typed raw SQL query.
func (*RawQuery[T]) First ¶
First executes the query, fetching at most one row, and returns ErrNotFound if no rows are returned.
type ReadOnlyDriver ¶
type ReadOnlyDriver interface {
ReadOnly() bool
}
ReadOnlyDriver marks a driver that routes reads to a replica. Lock-bearing queries reject such drivers before invoking Query.
type RelationMutation ¶
type RelationMutation struct {
// contains filtered or unexported fields
}
RelationMutation performs attach, detach, and replace atomically on a join table. All target keys are validated before a transaction starts.
func NewRelationMutation ¶
func NewRelationMutation(drv Driver, joinTable, parentColumn, targetColumn string, parentKey any) *RelationMutation
func (*RelationMutation) AttachRows ¶
func (m *RelationMutation) AttachRows(ctx context.Context, rows ...RelationRow) (int64, error)
type RelationRow ¶
type RelationRow struct {
Target any
Payload []Assignment
}
RelationRow is one join-table row. It supports through-row payloads while preserving deterministic column order.
type RestoreBuilder ¶
type RestoreBuilder[T any] struct { // contains filtered or unexported fields }
RestoreBuilder clears a declared soft-delete field without changing the query visibility policy.
func NewRestore ¶
func NewRestore[T any](drv Driver, table, deletedColumn string, options ...MutationOption) *RestoreBuilder[T]
func (*RestoreBuilder[T]) Exec ¶
func (b *RestoreBuilder[T]) Exec(ctx context.Context) (int64, error)
func (*RestoreBuilder[T]) Where ¶
func (b *RestoreBuilder[T]) Where(preds ...Pred[T]) *RestoreBuilder[T]
type Result ¶
type Result interface {
RowsAffected() int64
}
Result is the outcome of a database execution (non-SELECT query).
type ResultFieldSpec ¶
type ResultFieldSpec struct {
Name string
GoName string
Column string
Ordinal int
Type TypeRef
Nullable bool
Scanner string
}
ResultFieldSpec maps one database result column to a Go field.
type ResultMode ¶
type ResultMode string
ResultMode controls the generated execution method for a named SQL query.
const ( // ResultRows returns every row as a slice. It is the default mode. ResultRows ResultMode = "rows" // ResultOne returns exactly one row and reports ErrNotFound or // ErrTooManyRows when the cardinality does not match. ResultOne ResultMode = "one" // ResultFirst returns the first row and reports ErrNotFound for an empty // result. ResultFirst ResultMode = "first" // ResultIterate streams rows to a callback. ResultIterate ResultMode = "iterate" // ResultExec executes command SQL and returns affected rows. ResultExec ResultMode = "exec" )
type ResultSpec ¶
type ResultSpec struct {
Mode ResultMode
Type TypeRef
GoName string
Fields []ResultFieldSpec
// Partial permits declared fields to be absent from a result projection.
// Unknown columns remain errors.
Partial bool
}
ResultSpec describes the explicit result mapping for a query.
type RetryOptions ¶
RetryOptions makes transaction retries explicit and bounded.
func DefaultRetryOptions ¶
func DefaultRetryOptions() RetryOptions
DefaultRetryOptions returns a conservative bounded retry policy.
type Rows ¶
type Rows interface {
Next() bool
Columns() ([]string, error)
Values() ([]any, error)
Close()
Err() error
}
Rows represents the database result rows.
type SavepointDriver ¶
type SavepointDriver interface {
Savepoint(ctx context.Context, name string) error
ReleaseSavepoint(ctx context.Context, name string) error
RollbackToSavepoint(ctx context.Context, name string) error
}
SavepointDriver is implemented by transaction drivers that support nested transaction scopes without opening a second database transaction.
It is deliberately optional: drivers can continue to implement TxDriver while reporting ErrUnsupported for savepoint-dependent operations.
type SavepointOptions ¶
type SavepointOptions struct {
Prefix string
}
SavepointOptions controls the deterministic name prefix used by nested transaction scopes.
type Scope ¶
type Scope struct{ Aliases []string }
Scope is the set of source aliases visible to a selectable node.
type SelectExpr ¶
type SelectExpr interface {
As(string) SelectExpr
// contains filtered or unexported methods
}
SelectExpr is an expression that may appear in a SELECT or GROUP BY list. Column handles implement this interface. Computed expressions are created by the aggregate helpers below.
func As ¶
func As(expr SelectExpr, alias string) SelectExpr
As gives a selected expression a stable SQL alias.
func Avg ¶
func Avg(column SelectExpr) SelectExpr
Avg returns AVG(column) as a selectable expression.
func Count ¶
func Count(column SelectExpr) SelectExpr
Count returns COUNT(column) as a selectable expression.
func Max ¶
func Max(column SelectExpr) SelectExpr
Max returns MAX(column) as a selectable expression.
func Min ¶
func Min(column SelectExpr) SelectExpr
Min returns MIN(column) as a selectable expression.
func NestedProjection ¶
func NestedProjection(prefix string, exprs ...SelectExpr) []SelectExpr
NestedProjection gives a group of expressions stable flat aliases suitable for nested destination structs.
func OuterColumn ¶
func OuterColumn(ref ColumnRef) SelectExpr
OuterColumn renders a declared correlation reference.
func Scalar ¶
func Scalar[T any](s Subquery[T]) SelectExpr
Scalar turns a one-column subquery into a SELECT expression.
func Slot ¶
func Slot(expr SelectExpr, alias string, nullable ...bool) SelectExpr
Slot assigns explicit scanner metadata to an expression.
func Sum ¶
func Sum(column SelectExpr) SelectExpr
Sum returns SUM(column) as a selectable expression.
type Selectable ¶
type Selectable interface {
// contains filtered or unexported methods
}
Selectable is a query node that can be used as a subquery or CTE body. Query and Subquery are the constructors provided by this package; the unexported methods deliberately prevent arbitrary SQL nodes from entering a typed composition tree.
type Shape ¶
type Shape struct {
Slots []ProjectionSlot
}
Shape describes the values produced by a selectable node.
type Subquery ¶
type Subquery[T any] struct { Source *Query[T] Shape Shape // contains filtered or unexported fields }
Subquery is a typed selectable node. Correlate must be used to declare every outer reference used by the node.
func AsSubquery ¶
AsSubquery turns a query into a selectable node.
type TextCol ¶
type TextCol[T any] struct { // contains filtered or unexported fields }
TextCol is a typed text column handle.
func (TextCol[T]) ContainsFold ¶
func (TextCol) Expr ¶
func (c TextCol) Expr() MutationExpr
Expr exposes the column as a typed mutation expression. All generated column handles inherit this method through columnBase.
type TimeCol ¶
type TimeCol[T any] struct { // contains filtered or unexported fields }
TimeCol is a typed time column handle.
func (TimeCol) Expr ¶
func (c TimeCol) Expr() MutationExpr
Expr exposes the column as a typed mutation expression. All generated column handles inherit this method through columnBase.
type TxDriver ¶
type TxDriver interface {
Driver
Commit(ctx context.Context) error
Rollback(ctx context.Context) error
Unwrap() any
}
TxDriver is a Driver that runs in the context of a transaction.
type TxOptions ¶
type TxOptions struct {
Isolation IsolationLevel
ReadOnly bool
}
TxOptions holds the options for starting a transaction.
type TypeRef ¶
type TypeRef struct {
PackagePath string `json:"packagePath,omitempty"`
Name string `json:"name"`
Pointer bool `json:"pointer,omitempty"`
Type reflect.Type `json:"-"`
}
TypeRef describes a Go type used by a named SQL declaration. TypeRef values are normally created with TypeOf so the generator can preserve imports and named types without requiring the declaration package to expose strings.
func TypeRefFrom ¶
TypeRefFrom creates a generator-visible reference from a reflect type.
type UpdateBuilder ¶
type UpdateBuilder[T any] struct { // contains filtered or unexported fields }
UpdateBuilder is an explicit UPDATE builder. It returns affected rows from Exec and can also use Save to fetch a model through RETURNING *.
func NewUpdate ¶
func NewUpdate[T any](drv Driver, table string, options ...MutationOption) *UpdateBuilder[T]
func NewUpdateOne ¶
func NewUpdateOne[T any](drv Driver, table, idColumn string, id any, options ...MutationOption) *UpdateBuilder[T]
func (*UpdateBuilder[T]) Clear ¶
func (b *UpdateBuilder[T]) Clear(column string) *UpdateBuilder[T]
func (*UpdateBuilder[T]) ClearSensitive ¶
func (b *UpdateBuilder[T]) ClearSensitive(column string) *UpdateBuilder[T]
ClearSensitive clears a sensitive update field and keeps it redacted in observer notifications.
func (*UpdateBuilder[T]) Returning ¶
func (b *UpdateBuilder[T]) Returning(exprs ...SelectExpr) *UpdateBuilder[T]
Returning selects a typed projection for an update mutation.
func (*UpdateBuilder[T]) Set ¶
func (b *UpdateBuilder[T]) Set(column string, value any) *UpdateBuilder[T]
func (*UpdateBuilder[T]) SetExpr ¶
func (b *UpdateBuilder[T]) SetExpr(column string, expression MutationExpr) *UpdateBuilder[T]
SetExpr assigns an expression without reading the current row first.
func (*UpdateBuilder[T]) SetNillable ¶
func (b *UpdateBuilder[T]) SetNillable(column string, value any) *UpdateBuilder[T]
func (*UpdateBuilder[T]) SetNillableSensitive ¶
func (b *UpdateBuilder[T]) SetNillableSensitive(column string, value any) *UpdateBuilder[T]
SetNillableSensitive is SetNillable with observer redaction enabled.
func (*UpdateBuilder[T]) SetSensitive ¶
func (b *UpdateBuilder[T]) SetSensitive(column string, value any) *UpdateBuilder[T]
SetSensitive marks an update argument as sensitive for observer redaction.
func (*UpdateBuilder[T]) Where ¶
func (b *UpdateBuilder[T]) Where(preds ...Pred[T]) *UpdateBuilder[T]
func (*UpdateBuilder[T]) WithOptimisticLock ¶
func (b *UpdateBuilder[T]) WithOptimisticLock(column string, expected any) *UpdateBuilder[T]
WithOptimisticLock adds version = expected to the predicate and increments the version in the same UPDATE statement. Zero affected rows become ErrConflict and are never retried implicitly.
type UpsertBuilder ¶
type UpsertBuilder[T any] struct { // contains filtered or unexported fields }
UpsertBuilder renders and executes an atomic INSERT ... ON CONFLICT plan.
func NewUpsert ¶
func NewUpsert[T any](drv Driver, table string, options ...MutationOption) *UpsertBuilder[T]
func (*UpsertBuilder[T]) DoNothing ¶
func (b *UpsertBuilder[T]) DoNothing() *UpsertBuilder[T]
func (*UpsertBuilder[T]) OnColumns ¶
func (b *UpsertBuilder[T]) OnColumns(columns ...ColumnRef) *UpsertBuilder[T]
func (*UpsertBuilder[T]) OnConflict ¶
func (b *UpsertBuilder[T]) OnConflict(target ConflictTarget) *UpsertBuilder[T]
func (*UpsertBuilder[T]) OnConstraint ¶
func (b *UpsertBuilder[T]) OnConstraint(name string) *UpsertBuilder[T]
func (*UpsertBuilder[T]) Plan ¶
func (b *UpsertBuilder[T]) Plan() UpsertPlan
func (*UpsertBuilder[T]) Returning ¶
func (b *UpsertBuilder[T]) Returning(exprs ...SelectExpr) *UpsertBuilder[T]
func (*UpsertBuilder[T]) Set ¶
func (b *UpsertBuilder[T]) Set(column string, value any) *UpsertBuilder[T]
func (*UpsertBuilder[T]) SetExpr ¶
func (b *UpsertBuilder[T]) SetExpr(column string, expression MutationExpr) *UpsertBuilder[T]
func (*UpsertBuilder[T]) SetSensitive ¶
func (b *UpsertBuilder[T]) SetSensitive(column string, value any) *UpsertBuilder[T]
func (*UpsertBuilder[T]) Update ¶
func (b *UpsertBuilder[T]) Update(assignments ...Assignment) *UpsertBuilder[T]
func (*UpsertBuilder[T]) Where ¶
func (b *UpsertBuilder[T]) Where(pred any) *UpsertBuilder[T]
type UpsertPlan ¶
type UpsertPlan struct {
Insert []Assignment
Conflict ConflictTarget
Update []Assignment
Predicate any
Returning Projection
}
UpsertPlan is the serializable mutation plan used by UpsertBuilder.
type ValueCol ¶
ValueCol is a generic scalar handle for UUID, byte, and application-defined values whose comparison type is not one of the built-in text/numeric types.
func NewValueCol ¶
NewValueCol creates a generic typed value handle.
func (ValueCol) As ¶
func (c ValueCol) As(alias string) SelectExpr
As gives a column a SELECT alias.
func (ValueCol) Expr ¶
func (c ValueCol) Expr() MutationExpr
Expr exposes the column as a typed mutation expression. All generated column handles inherit this method through columnBase.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bind defines dialect-neutral structures for binding untrusted input.
|
Package bind defines dialect-neutral structures for binding untrusted input. |
|
dashsort
Package dashsort implements the generated allowlist-based dash-sort codec.
|
Package dashsort implements the generated allowlist-based dash-sort codec. |
|
rhs
Package rhs implements the generated right-hand-side filter codec.
|
Package rhs implements the generated right-hand-side filter codec. |
|
Package bindable defines opt-in schema annotations consumed by generated request binders.
|
Package bindable defines opt-in schema annotations consumed by generated request binders. |
|
cmd
|
|
|
funq
command
Command funq provides schema generation and migration tooling.
|
Command funq provides schema generation and migration tooling. |
|
Package dialect defines database dialect contracts and shared SQL writing.
|
Package dialect defines database dialect contracts and shared SQL writing. |
|
dialecttest
Package dialecttest provides reusable conformance tests for dialects.
|
Package dialecttest provides reusable conformance tests for dialects. |
|
postgres
Package postgres implements the PostgreSQL dialect.
|
Package postgres implements the PostgreSQL dialect. |
|
Package driver contains concrete adapters for Funq's root driver contracts.
|
Package driver contains concrete adapters for Funq's root driver contracts. |
|
pgxdriver
module
|
|
|
Package gen loads schemas and coordinates deterministic code generation.
|
Package gen loads schemas and coordinates deterministic code generation. |
|
emit
Package emit contains Funq's built-in deterministic source emitters.
|
Package emit contains Funq's built-in deterministic source emitters. |
|
ir
Package ir defines Funq's stable, resolved, serializable schema graph.
|
Package ir defines Funq's stable, resolved, serializable schema graph. |
|
internal
|
|
|
cli
Package cli implements the command-line interface while keeping command parsing separate from library behavior.
|
Package cli implements the command-line interface while keeping command parsing separate from library behavior. |
|
config
Package config loads the funq.yaml project file that anchors schema, generated output, migration, and development-database locations for every CLI command.
|
Package config loads the funq.yaml project file that anchors schema, generated output, migration, and development-database locations for every CLI command. |
|
testpg
Package testpg provides isolated PostgreSQL schemas for integration tests.
|
Package testpg provides isolated PostgreSQL schemas for integration tests. |
|
Package migrate provides desired-state DDL, introspection, diffing, and planning.
|
Package migrate provides desired-state DDL, introspection, diffing, and planning. |
|
Package schema defines declaration-time entity values.
|
Package schema defines declaration-time entity values. |
|
check
Package check declares application-level SQL check constraints.
|
Package check declares application-level SQL check constraints. |
|
edge
Package edge defines schema relationship builders.
|
Package edge defines schema relationship builders. |
|
field
Package field defines typed schema field builders.
|
Package field defines typed schema field builders. |
|
index
Package index defines schema index builders.
|
Package index defines schema index builders. |
|
mixin
Package mixin defines reusable groups of schema declarations, including application-side and database-side primary-key generators.
|
Package mixin defines reusable groups of schema declarations, including application-side and database-side primary-key generators. |
|
Package types defines custom value and scanner extension contracts.
|
Package types defines custom value and scanner extension contracts. |