orm

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package orm provides the runtime ORM for querying and mutating application models.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("orm: not found")

Functions

This section is empty.

Types

type AfterCreateHook added in v0.1.1

type AfterCreateHook interface {
	AfterCreate(context.Context) error
}

type AfterDeleteHook added in v0.1.1

type AfterDeleteHook interface {
	AfterDelete(context.Context) error
}

type AfterFindHook added in v0.1.1

type AfterFindHook interface {
	AfterFind(context.Context) error
}

type AfterUpdateHook added in v0.1.1

type AfterUpdateHook interface {
	AfterUpdate(context.Context) error
}

type Attribute

type Attribute struct {
	Key   string
	Value any
}

Attribute is a key-value pair attached to spans and metrics.

type BeforeCreateHook added in v0.1.1

type BeforeCreateHook interface {
	BeforeCreate(context.Context) error
}

type BeforeDeleteHook added in v0.1.1

type BeforeDeleteHook interface {
	BeforeDelete(context.Context) error
}

type BeforeFindHook added in v0.1.1

type BeforeFindHook interface {
	BeforeFind(context.Context) error
}

type BeforeUpdateHook added in v0.1.1

type BeforeUpdateHook interface {
	BeforeUpdate(context.Context) error
}

type Config

type Config struct {
	DB                  *sql.DB
	Tx                  *sql.Tx
	Dialect             dialect.Dialect
	DriverName          string
	Schema              *schema.Schema
	Logger              Logger
	Observability       ObservabilityConfig
	Access              access.Engine
	PrepareStatements   bool
	SoftDeleteByDefault bool
}

type Counter

type Counter interface {
	Add(context.Context, float64, ...Attribute)
}

Counter records monotonic values.

type DB

type DB struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config) *DB

func (*DB) Close added in v0.1.1

func (db *DB) Close() error

func (*DB) Dialect added in v0.1.1

func (db *DB) Dialect() dialect.Dialect

func (*DB) Ping added in v0.1.1

func (db *DB) Ping(ctx context.Context) error

func (*DB) PingContext added in v0.1.1

func (db *DB) PingContext(ctx context.Context) error

func (*DB) SQLDB added in v0.1.1

func (db *DB) SQLDB() *sql.DB

func (*DB) Stats added in v0.1.1

func (db *DB) Stats() sql.DBStats

func (*DB) Tx

func (db *DB) Tx(ctx context.Context, fn func(*Session) error) error

func (*DB) WithContext

func (db *DB) WithContext(ctx context.Context) *Session

func (*DB) WithPolicy added in v0.1.1

func (db *DB) WithPolicy(policy access.Policy) *Session

type Histogram

type Histogram interface {
	Record(context.Context, float64, ...Attribute)
}

Histogram records duration or size distributions.

type Logger

type Logger interface {
	Printf(string, ...any)
}

type Meter

type Meter interface {
	Counter(name string) Counter
	Histogram(name string) Histogram
}

Meter creates counters and histograms.

type MeterProvider

type MeterProvider interface {
	Meter(name string) Meter
}

MeterProvider creates named meters.

type Observability added in v0.1.10

type Observability = ObservabilityConfig

Observability is an alias kept for the public API documented in ADR-026.

type ObservabilityConfig

type ObservabilityConfig struct {
	Tracing            bool
	Metrics            bool
	TraceSQL           TraceSQLMode
	SQLLogging         SQLLogMode
	SlowQueryThreshold time.Duration
	MaskParameters     bool
	MaskedFields       []string
	Logger             ObservabilityLogger
	TracerProvider     TracerProvider
	MeterProvider      MeterProvider
}

ObservabilityConfig configures tracing, metrics, and SQL visibility.

func DefaultObservabilityConfig

func DefaultObservabilityConfig() ObservabilityConfig

DefaultObservabilityConfig returns the default observability configuration.

func (ObservabilityConfig) Enabled

func (c ObservabilityConfig) Enabled() bool

Enabled reports whether any observability feature is active.

func (ObservabilityConfig) Normalized

Normalized returns a copy with defaults applied.

func (ObservabilityConfig) ShouldMask

func (c ObservabilityConfig) ShouldMask(field string) bool

ShouldMask reports whether a field name should be redacted in logs.

func (ObservabilityConfig) Validate

func (c ObservabilityConfig) Validate() error

Validate checks that the configuration is internally consistent.

type ObservabilityLogger

type ObservabilityLogger interface {
	LogSQL(context.Context, SQLLogEntry)
	LogError(context.Context, error)
}

ObservabilityLogger receives SQL logs and error events.

type QueryOption

type QueryOption func(*queryState)

func Limit

func Limit(n int) QueryOption

func Offset

func Offset(n int) QueryOption

func OrderBy

func OrderBy(expr string) QueryOption

func Where

func Where(expr string, args ...any) QueryOption

type SQLLogEntry

type SQLLogEntry struct {
	SQL          string
	Args         []any
	Duration     time.Duration
	AffectedRows int64
	Timestamp    time.Time
	Err          error
	Slow         bool
	Visibility   TraceSQLMode
	Driver       string
	Dialect      string
	Operation    string
	Table        string
}

SQLLogEntry captures a single SQL log event.

type SQLLogMode

type SQLLogMode string

SQLLogMode controls how SQL statements are reported by the legacy logger path.

const (
	SQLLogDisabled   SQLLogMode = "disabled"
	SQLLogErrorsOnly SQLLogMode = "errors_only"
	SQLLogSlow       SQLLogMode = "slow_queries"
	SQLLogDebug      SQLLogMode = "debug"
	SQLLogTrace      SQLLogMode = "trace"
)

type Session

type Session struct {
	// contains filtered or unexported fields
}

func (*Session) Count added in v0.1.8

func (s *Session) Count(model any, opts ...QueryOption) (int64, error)

Count returns the number of rows matching the model type and query options.

func (*Session) Create

func (s *Session) Create(model any) error

func (*Session) Delete

func (s *Session) Delete(model any) error

func (*Session) Find

func (s *Session) Find(dest any, opts ...QueryOption) error

func (*Session) FindOne

func (s *Session) FindOne(dest any, opts ...QueryOption) error

func (*Session) Load added in v0.1.1

func (s *Session) Load(dest any, relation string) error

func (*Session) Preload added in v0.1.1

func (s *Session) Preload(dest any, relations ...string) error

func (*Session) SoftDelete

func (s *Session) SoftDelete(model any) error

func (*Session) Tx

func (s *Session) Tx(fn func(*Session) error) error

func (*Session) Update

func (s *Session) Update(model any) error

func (*Session) UpdateWhere added in v0.1.9

func (s *Session) UpdateWhere(model any, opts ...QueryOption) error

UpdateWhere updates rows matching explicit query filters.

func (*Session) Upsert

func (s *Session) Upsert(model any) error

func (*Session) WithContext added in v0.1.1

func (s *Session) WithContext(ctx context.Context) *Session

func (*Session) WithDeleted

func (s *Session) WithDeleted() *Session

func (*Session) WithPolicy added in v0.1.1

func (s *Session) WithPolicy(policy access.Policy) *Session

type Span

type Span interface {
	End()
	RecordError(error)
	SetAttributes(...Attribute)
}

Span represents an active trace span.

type SpanOption

type SpanOption interface {
	// contains filtered or unexported methods
}

SpanOption configures span creation.

type TraceSQLMode added in v0.1.10

type TraceSQLMode string

TraceSQLMode controls how much SQL detail is exposed through traces.

const (
	TraceSQLDisabled          TraceSQLMode = "disabled"
	TraceSQLMetadata          TraceSQLMode = "metadata"
	TraceSQLStatement         TraceSQLMode = "statement"
	TraceSQLStatementWithArgs TraceSQLMode = "statement_with_args"
)

type Tracer

type Tracer interface {
	Start(context.Context, string, ...SpanOption) (context.Context, Span)
}

Tracer starts spans.

type TracerProvider

type TracerProvider interface {
	Tracer(name string) Tracer
}

TracerProvider creates named tracers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL