Versions in this module Expand all Collapse all v0 v0.1.2 Sep 25, 2026 v0.1.1 Sep 25, 2026 v0.1.0 Sep 25, 2026 Changes in this version + var ErrClosed = errors.New("orm: transaction is closed") + var ErrConstraint = errors.New("orm: constraint violated") + var ErrInvalidIdentifier = errors.New("orm: invalid identifier") + var ErrNoRowsAffected = errors.New("orm: no rows affected") + var ErrNotFound = errors.New("orm: record not found") + var ErrUnsafeMutation = errors.New("orm: update or delete requires a predicate") + var ErrUnsupported = errors.New("orm: unsupported feature") + func CheckIdentifier(name string) error + func CheckRowsAffected(result interface{ ... }) error + func ColumnName(fieldName string) string + func IsCheckViolation(err error) bool + func IsForeignKeyViolation(err error) bool + func IsNotNullViolation(err error) bool + func IsUniqueViolation(err error) bool + func PivotColumnFor(structName string) string + func TableNameFor(structName string) string + type AfterCreateHook interface + AfterCreate func(context.Context) error + type AfterDeleteHook interface + AfterDelete func(context.Context) error + type AfterUpdateHook interface + AfterUpdate func(context.Context) error + type BeforeCreateHook interface + BeforeCreate func(context.Context) error + type BeforeDeleteHook interface + BeforeDelete func(context.Context) error + type BeforeUpdateHook interface + BeforeUpdate func(context.Context) error + type ConstraintError struct + Cause error + Columns []string + Constraint string + Kind ConstraintKind + Table string + func (e *ConstraintError) Error() string + func (e *ConstraintError) Is(target error) bool + func (e *ConstraintError) Unwrap() error + type ConstraintKind int + const ConstraintCheck + const ConstraintForeignKey + const ConstraintNotNull + const ConstraintUnique + const ConstraintUnknown + func (k ConstraintKind) String() string + type DB struct + func Open(db *sql.DB, dialect Dialect, options ...Option) *DB + func (db *DB) Begin(ctx context.Context) (*Tx, error) + func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) + func (db *DB) Close() error + func (db *DB) Dialect() Dialect + func (db *DB) Exec(ctx context.Context, query string, args ...any) (sql.Result, error) + func (db *DB) Logger() Logger + func (db *DB) Model[T any]() *Query[T] + func (db *DB) Raw[T any](query string, args ...any) *RawQuery[T] + func (db *DB) Relation[Parent, Child any](parent *Parent, name string) *RelationHandle[Parent, Child] + func (db *DB) SQLDB() *sql.DB + func (db *DB) Transaction(ctx context.Context, fn func(*Tx) error) error + type Dialect interface + ClassifyError func(error) error + Name func() string + Placeholder func(int) string + Quote func(string) string + SupportsReturning func() bool + UpsertClause func(conflict, update []string) (string, error) + func MySQL() Dialect + func Postgres() Dialect + func SQLite() Dialect + type Field struct + func NewField[Model, Value any](column string) Field[Model, Value] + func (f Field[Model, Value]) Asc() Ordering + func (f Field[Model, Value]) Between(low, high Value) Predicate + func (f Field[Model, Value]) Column() string + func (f Field[Model, Value]) Desc() Ordering + func (f Field[Model, Value]) Eq(value Value) Predicate + func (f Field[Model, Value]) Gt(value Value) Predicate + func (f Field[Model, Value]) Gte(value Value) Predicate + func (f Field[Model, Value]) In(values ...Value) Predicate + func (f Field[Model, Value]) IsNotNull() Predicate + func (f Field[Model, Value]) IsNull() Predicate + func (f Field[Model, Value]) Lt(value Value) Predicate + func (f Field[Model, Value]) Lte(value Value) Predicate + func (f Field[Model, Value]) Ne(value Value) Predicate + func (f Field[Model, Value]) NotIn(values ...Value) Predicate + type FieldInfo struct + AutoIncrement bool + Column string + Index []int + Name string + PrimaryKey bool + Type reflect.Type + type Logger func(context.Context, QueryEvent) + type MappingError struct + Cause error + Column string + Model string + func (e *MappingError) Error() string + func (e *MappingError) Unwrap() error + type ModelInfo struct + ByColumn map[string]FieldInfo + ByName map[string]FieldInfo + ByRelation map[string]RelationInfo + CreatedAt *FieldInfo + Fields []FieldInfo + PrimaryKey *FieldInfo + PrimaryKeys []FieldInfo + Relations []RelationInfo + SoftDelete *FieldInfo + Table string + Type reflect.Type + UpdatedAt *FieldInfo + func ModelInfoFor[T any]() (*ModelInfo, error) + func (m *ModelInfo) Column(fieldName string) (string, bool) + func (m *ModelInfo) HasCompositeKey() bool + func (m *ModelInfo) HasSoftDelete() bool + type Numeric interface + type Operation string + const OpExec + const OpQuery + type Option func(*DB) + func WithDialect(dialect Dialect) Option + func WithLogger(logger Logger) Option + func WithSlogLogger(logger *slog.Logger) Option + type Ordering struct + func Asc(column string) Ordering + func Desc(column string) Ordering + func RawOrdering(sql string) Ordering + type Page struct + Items []T + Page int + PerPage int + Total int64 + TotalPages int + func (p *Page[T]) HasNext() bool + func (p *Page[T]) HasPrev() bool + type Predicate struct + func And(predicates ...Predicate) Predicate + func Between(column string, low, high any) Predicate + func Eq(column string, value any) Predicate + func Gt(column string, value any) Predicate + func Gte(column string, value any) Predicate + func In(column string, values ...any) Predicate + func IsNotNull(column string) Predicate + func IsNull(column string) Predicate + func Like(column string, pattern string) Predicate + func Lt(column string, value any) Predicate + func Lte(column string, value any) Predicate + func Ne(column string, value any) Predicate + func Not(predicate Predicate) Predicate + func NotIn(column string, values ...any) Predicate + func NotLike(column string, pattern string) Predicate + func Or(predicates ...Predicate) Predicate + func RawPredicate(sql string, args ...any) Predicate + func (p Predicate) And(other Predicate) Predicate + func (p Predicate) IsZero() bool + func (p Predicate) Or(other Predicate) Predicate + type Query struct + func (q *Query[T]) All(ctx context.Context) ([]T, error) + func (q *Query[T]) As[R any]() *Query[R] + func (q *Query[T]) Avg[V Numeric](ctx context.Context, column string) (V, error) + func (q *Query[T]) Count(ctx context.Context) (int64, error) + func (q *Query[T]) Create(ctx context.Context, entity *T) (sql.Result, error) + func (q *Query[T]) CreateBatch(ctx context.Context, entities []*T) (sql.Result, error) + func (q *Query[T]) Delete(ctx context.Context, entity *T) (sql.Result, error) + func (q *Query[T]) DeleteAll(ctx context.Context) (sql.Result, error) + func (q *Query[T]) DeleteSQL(entity *T) (string, []any, error) + func (q *Query[T]) Distinct() *Query[T] + func (q *Query[T]) Exists(ctx context.Context) (bool, error) + func (q *Query[T]) Find(ctx context.Context, keys ...any) (*T, error) + func (q *Query[T]) First(ctx context.Context) (*T, error) + func (q *Query[T]) ForceDelete(ctx context.Context, entity *T) (sql.Result, error) + func (q *Query[T]) ForceDeleteAll(ctx context.Context) (sql.Result, error) + func (q *Query[T]) GroupBy(columns ...string) *Query[T] + func (q *Query[T]) Having(predicates ...Predicate) *Query[T] + func (q *Query[T]) InsertIgnore(ctx context.Context, entity *T, conflict ...string) (sql.Result, error) + func (q *Query[T]) InsertSQL(entity *T) (string, []any, error) + func (q *Query[T]) JoinTable(table string, on Predicate) *Query[T] + func (q *Query[T]) Join[U any](on Predicate) *Query[T] + func (q *Query[T]) LeftJoinTable(table string, on Predicate) *Query[T] + func (q *Query[T]) LeftJoin[U any](on Predicate) *Query[T] + func (q *Query[T]) Limit(limit int) *Query[T] + func (q *Query[T]) Max[V any](ctx context.Context, column string) (V, error) + func (q *Query[T]) Min[V any](ctx context.Context, column string) (V, error) + func (q *Query[T]) Offset(offset int) *Query[T] + func (q *Query[T]) OnlyTrashed() *Query[T] + func (q *Query[T]) OrderBy(orderings ...Ordering) *Query[T] + func (q *Query[T]) Paginate(ctx context.Context, page, perPage int) (*Page[T], error) + func (q *Query[T]) Pluck[V any](ctx context.Context, column string) ([]V, error) + func (q *Query[T]) Restore(ctx context.Context, entity *T) (sql.Result, error) + func (q *Query[T]) SQL() (string, []any) + func (q *Query[T]) Scope(scopes ...Scope[T]) *Query[T] + func (q *Query[T]) Select(columns ...string) *Query[T] + func (q *Query[T]) Sum[V Numeric](ctx context.Context, column string) (V, error) + func (q *Query[T]) Table(name string) *Query[T] + func (q *Query[T]) Update(ctx context.Context, entity *T) (sql.Result, error) + func (q *Query[T]) UpdateAll(ctx context.Context, values map[string]any) (sql.Result, error) + func (q *Query[T]) UpdateSQL(entity *T, columns ...string) (string, []any, error) + func (q *Query[T]) Upsert(ctx context.Context, entity *T, conflict []string, update ...string) (sql.Result, error) + func (q *Query[T]) Where(predicates ...Predicate) *Query[T] + func (q *Query[T]) With(paths ...string) *Query[T] + func (q *Query[T]) WithTrashed() *Query[T] + type QueryEvent struct + Args []any + Duration time.Duration + Err error + Operation Operation + Rows int64 + SQL string + func (e QueryEvent) String() string + type RawQuery struct + func (q *RawQuery[T]) All(ctx context.Context) ([]T, error) + func (q *RawQuery[T]) First(ctx context.Context) (*T, error) + func (q *RawQuery[T]) SQL() (string, []any) + type RelationHandle struct + func (h *RelationHandle[Parent, Child]) Add(ctx context.Context, children ...*Child) error + func (h *RelationHandle[Parent, Child]) Attach(ctx context.Context, children ...*Child) error + func (h *RelationHandle[Parent, Child]) AttachKeys(ctx context.Context, keys ...any) error + func (h *RelationHandle[Parent, Child]) Count(ctx context.Context) (int64, error) + func (h *RelationHandle[Parent, Child]) Detach(ctx context.Context, children ...*Child) error + func (h *RelationHandle[Parent, Child]) DetachKeys(ctx context.Context, keys ...any) error + func (h *RelationHandle[Parent, Child]) Load(ctx context.Context) error + func (h *RelationHandle[Parent, Child]) Query() *Query[Child] + func (h *RelationHandle[Parent, Child]) Remove(ctx context.Context, children ...*Child) error + func (h *RelationHandle[Parent, Child]) Sync(ctx context.Context, children ...*Child) error + func (h *RelationHandle[Parent, Child]) SyncKeys(ctx context.Context, keys ...any) error + func (h *RelationHandle[Parent, Child]) Toggle(ctx context.Context, children ...*Child) error + func (h *RelationHandle[Parent, Child]) ToggleKeys(ctx context.Context, keys ...any) error + type RelationInfo struct + ForeignKeyField string + Index []int + Kind RelationKind + Name string + PivotForeignKey string + PivotTable string + PivotTargetKey string + ReferencesField string + Target reflect.Type + type RelationKind int + const BelongsTo + const HasMany + const HasOne + const ManyToMany + const RelationNone + func (k RelationKind) String() string + type Scope func(*Query[T]) *Query[T] + type TableNamer interface + TableName func() string + type TagInfo struct + AutoCreateTime bool + AutoIncrement bool + AutoUpdateTime bool + Column string + PivotForeignKey string + PivotTable string + PivotTargetKey string + PrimaryKey bool + References string + Relation RelationKind + RelationKey string + Skip bool + SoftDelete bool + func ParseTag(value string) TagInfo + type Tx struct + func (tx *Tx) AfterCommit(callback func(context.Context) error) error + func (tx *Tx) Commit() error + func (tx *Tx) CommitContext(ctx context.Context) error + func (tx *Tx) Dialect() Dialect + func (tx *Tx) Exec(ctx context.Context, query string, args ...any) (sql.Result, error) + func (tx *Tx) Model[T any]() *Query[T] + func (tx *Tx) Raw[T any](query string, args ...any) *RawQuery[T] + func (tx *Tx) Relation[Parent, Child any](parent *Parent, name string) *RelationHandle[Parent, Child] + func (tx *Tx) ReleaseSavepoint(ctx context.Context, name string) error + func (tx *Tx) Rollback() error + func (tx *Tx) RollbackTo(ctx context.Context, name string) error + func (tx *Tx) Savepoint(ctx context.Context, name string) error + type UnsupportedFeatureError struct + Dialect string + Feature string + func (e *UnsupportedFeatureError) Error() string + func (e *UnsupportedFeatureError) Is(target error) bool