Documentation
¶
Index ¶
- func Creator[C CreateEntity](db *sql.DB, table string) gimpl.Creator[C]
- func Finder[E Entity](db *sql.DB, table string) gimpl.Finder[E]
- func FromExpr(e gimpl.Expr) (squirrel.Sqlizer, error)
- func FromSorts(s gimpl.Sorts, query squirrel.SelectBuilder) (_ squirrel.SelectBuilder, reverse *squirrel.SelectBuilder, err error)
- func Remover[E Entity](db *sql.DB, table string) gimpl.Remover[E]
- func Saver[S SaveEntity](db *sql.DB, table string) gimpl.Saver[S]
- func TxOpts(ctx context.Context, db *sql.DB, opts any) (txOpts, error)
- func Updater[U UpdateEntity](db *sql.DB, table string) gimpl.Updater[U]
- type CreateEntity
- type CreateTx
- type Entity
- type SaveEntity
- type Tx
- type TxOpt
- type UpdateEntity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Creator ¶
Creator returns a gimpl.Creator for the specified entity type and table name C must implement the CreateEntity interface
func Finder ¶
Finder returns a gimpl.Finder for the specified entity type and table name E must implement the Entity interface
func FromExpr ¶
FromExpr converts an gimpl.Expr logical/quantified expression tree into a squirrel.Sqlizer fragment and a slice of args that is compatible with postgres.
Conventions implemented:
- A CondExpr whose Field has no dots (e.g. "status") and is NOT nested beneath a quantifier is treated as a direct column comparison: status = ?
- A CondExpr whose Field contains dots OR that appears beneath a quantifier context is treated as a JSONB path comparison. The first segment before the first dot (or the quantifier's array element alias) is the JSONB root. Remaining segments become a jsonb path using the '#>' operator.
- Quantifiers (ANY / ALL) over a jsonb array path are translated into EXISTS / NOT EXISTS with jsonb_array_elements(). Nested quantifiers are supported (aliases are generated q0, q1, ...).
- IN / NIN for JSON values rely on the jsonb containment operator '<@' Column IN / NIN use '= ANY (?)' / '!= ALL (?)' patterns.
func FromSorts ¶
func FromSorts(s gimpl.Sorts, query squirrel.SelectBuilder) (_ squirrel.SelectBuilder, reverse *squirrel.SelectBuilder, err error)
FromSorts returns the given query with sorting and cursors applied. It also returns a reverse query for fetching the previous first result required for the prev cursor.
func Remover ¶
Remover returns a gimpl.Remover for the specified entity type and table name E must implement the Entity interface
Types ¶
type CreateEntity ¶
type CreateEntity interface {
gimpl.CreateEntity
// CreatePgColumns returns a slice of column names used for creation operations.
// Returned values should be static and not vary between calls
CreatePgColumns() []string
// CreatePgColumnVals returns a slice of the fields used for writing to the entity during creation operations
// Returned values should not be dynamic and must correspond to the columns returned by CreatePgColumns
CreatePgColumnVals() []any
}
CreateEntity is an extension of gimpl.CreateEntity for Postgres creation operations. DO NOT USE POINTER RECEIVERS
type CreateTx ¶
func NewTxCreator ¶
type Entity ¶
type Entity interface {
gimpl.Entity
// PgColumn returns the column name used for the given field
PgColumn(field string) string
// PgColumns returns a slice of column names used for data retrieval.
// Returned values should be static and not vary between calls
PgColumns() []string
// NewWithPgColumnPtrs returns a new entity and a slice of pointers to the fields used for writing to the entity during data retrieval
// Returned values should not be dynamic and must correspond to the columns returned by PgColumns
// The reason for creating a new entity is that without pointer receivers, the method cannot modify the original entity
NewWithPgColumnPtrs() (any, []any)
}
Entity is an extension of gimpl.Entity for Postgres operations. DO NOT USE POINTER RECEIVERS
type SaveEntity ¶
type SaveEntity interface {
CreateEntity
UpdateEntity
}
SaveEntity is an extension of gimpl.SaveEntity for Postgres create or update operations. DO NOT USE POINTER RECEIVERS
type Tx ¶
Tx wraps a sql.Tx to provide helper methods for committing or rolling back.
type TxOpt ¶
type TxOpt func(*txOpts)
func WithTx ¶
WithTx instructs the repository to use the provided transaction instead of creating a new one. Any error in creating or setting audit parameters must be handled before passing the Tx here.
func WithTxAutoFinalize ¶
func WithTxAutoFinalize() TxOpt
WithTxAutoFinalize instructs the repository to finalize the transaction after the operation completes.
type UpdateEntity ¶
type UpdateEntity interface {
gimpl.UpdateEntity
// IdentifyPgColumns returns a slice of column names used to identify unique records for update operations.
// Returned values should be static and not vary between calls
IdentifyPgColumns() []string
// IdentifyPgColumnVals returns a slice of the fields used to identify unique records for update operations
// Returned values should not be dynamic and must correspond to the columns returned by IdentifyPgColumns
IdentifyPgColumnVals() []any
// UpdatePgColumns returns a slice of column names used for update operations.
// Returned values should be static and not vary between calls
UpdatePgColumns() []string
// UpdatePgColumnVals returns a slice of the fields used for writing to the entity during update operations
// Returned values should not be dynamic and must correspond to the columns returned by UpdatePgColumns
UpdatePgColumnVals() []any
}
UpdateEntity is an extension of gimpl.UpdateEntity for Postgres update operations. DO NOT USE POINTER RECEIVERS