Documentation
¶
Overview ¶
Package gorm provides the GORM-based implementation of the Helix repository interfaces.
Index ¶
- func ColumnFor[T any](db *gormlib.DB, field string) (clause.Column, error)
- func Database(ctx context.Context, db *gormlib.DB, action string) (*gormlib.DB, error)
- func EscapeLike(value string) string
- func WrapError(action string, err error) error
- type ConnectionPoolConfig
- type DB
- type Repository
- func (r *Repository[T, ID]) Delete(ctx context.Context, id ID) error
- func (r *Repository[T, ID]) FindAll(ctx context.Context) ([]T, error)
- func (r *Repository[T, ID]) FindByID(ctx context.Context, id ID) (*T, error)
- func (r *Repository[T, ID]) FindWhere(ctx context.Context, filter data.Filter) ([]T, error)
- func (r *Repository[T, ID]) Paginate(ctx context.Context, page, size int) (data.Page[T], error)
- func (r *Repository[T, ID]) Save(ctx context.Context, entity *T) error
- func (r *Repository[T, ID]) WithTransaction(tx data.Transaction[*gormlib.DB]) data.Repository[T, ID, *gormlib.DB]
- type Transaction
- type TransactionManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EscapeLike ¶
EscapeLike escapes SQL LIKE wildcard characters for generated queries.
Types ¶
type ConnectionPoolConfig ¶
ConnectionPoolConfig holds database/sql connection-pool settings.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps a GORM database connection, hiding gorm.io types from other packages.
func OpenSQLite ¶
OpenSQLite opens a SQLite database at dsn using GORM with TranslateError enabled.
func (*DB) AutoMigrate ¶
AutoMigrate runs GORM AutoMigrate for the provided models.
func (*DB) Components ¶
Components returns the components to register in the DI container: the internal *gorm.DB, *TransactionManager, and *DB wrapper.
func (*DB) ConfigurePool ¶
func (d *DB) ConfigurePool(cfg ConnectionPoolConfig) error
ConfigurePool applies database/sql pool settings. Zero values are treated as no-op; negative values return an error.
type Repository ¶
Repository implements data.Repository using a GORM database handle.
func NewRepository ¶
func NewRepository[T, ID any](db *gormlib.DB) *Repository[T, ID]
NewRepository creates a GORM-backed repository. If db is nil, the returned repository is invalid: every method call will return an error wrapping errInvalidDB without panicking.
func (*Repository[T, ID]) Delete ¶
func (r *Repository[T, ID]) Delete(ctx context.Context, id ID) error
Delete removes the record matching id.
func (*Repository[T, ID]) FindAll ¶
func (r *Repository[T, ID]) FindAll(ctx context.Context) ([]T, error)
FindAll returns all records for T.
func (*Repository[T, ID]) FindByID ¶
func (r *Repository[T, ID]) FindByID(ctx context.Context, id ID) (*T, error)
FindByID returns the record matching id.
func (*Repository[T, ID]) Save ¶
func (r *Repository[T, ID]) Save(ctx context.Context, entity *T) error
Save creates or updates entity using GORM's traditional upsert semantics.
func (*Repository[T, ID]) WithTransaction ¶
func (r *Repository[T, ID]) WithTransaction(tx data.Transaction[*gormlib.DB]) data.Repository[T, ID, *gormlib.DB]
WithTransaction returns a new Repository bound to tx.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction wraps a GORM transaction handle for data.Repository.WithTransaction.
func NewTransaction ¶
func NewTransaction(db *gormlib.DB) Transaction
NewTransaction wraps db as a data.Transaction-compatible GORM transaction.
func (Transaction) Unwrap ¶
func (t Transaction) Unwrap() *gormlib.DB
Unwrap returns the wrapped GORM transaction handle.
type TransactionManager ¶
type TransactionManager struct {
// contains filtered or unexported fields
}
TransactionManager executes callbacks inside GORM transactions.
func NewTransactionManager ¶
func NewTransactionManager(db *gormlib.DB) *TransactionManager
NewTransactionManager creates a transaction manager backed by db. A nil db is reported when WithinTransaction is called.
func (*TransactionManager) WithinTransaction ¶
func (m *TransactionManager) WithinTransaction(ctx context.Context, fn func(context.Context, data.Transaction[*gormlib.DB]) error) error
WithinTransaction runs fn inside a GORM transaction. If ctx already carries a GORM transaction, fn joins it instead of creating a nested GORM transaction or savepoint.