Documentation
¶
Overview ¶
Package orm provides the runtime ORM for querying and mutating application models.
Index ¶
- Variables
- type AfterCreateHook
- type AfterDeleteHook
- type AfterFindHook
- type AfterUpdateHook
- type Attribute
- type BeforeCreateHook
- type BeforeDeleteHook
- type BeforeFindHook
- type BeforeUpdateHook
- type Config
- type Counter
- type DB
- func (db *DB) Begin(ctx context.Context) (*DB, error)
- func (db *DB) Close() error
- func (db *DB) Commit() error
- func (db *DB) Count(model any, opts ...QueryOption) (int64, error)
- func (db *DB) Create(model any) error
- func (db *DB) CreateMany(ctx context.Context, models any) error
- func (db *DB) Delete(model any) error
- func (db *DB) DeleteMany(ctx context.Context, models any) error
- func (db *DB) Dialect() dialect.Dialect
- func (db *DB) Find(dest any, opts ...QueryOption) error
- func (db *DB) FindOne(dest any, opts ...QueryOption) error
- func (db *DB) Ping(ctx context.Context) error
- func (db *DB) PingContext(ctx context.Context) error
- func (db *DB) Raw(ctx context.Context, query string, args ...any) *RawBuilder
- func (db *DB) Rollback() error
- func (db *DB) SQLDB() *sql.DB
- func (db *DB) SoftDelete(model any) error
- func (db *DB) Stats() sql.DBStats
- func (db *DB) Transaction(ctx context.Context, fn func(*DB) error) error
- func (db *DB) Tx(ctx context.Context, fn func(*Session) error) error
- func (db *DB) Update(model any) error
- func (db *DB) UpdateMany(ctx context.Context, models any) error
- func (db *DB) UpdateWhere(model any, opts ...QueryOption) error
- func (db *DB) Upsert(model any) error
- func (db *DB) WithContext(ctx context.Context) *Session
- func (db *DB) WithPolicy(policy access.Policy) *Session
- type Histogram
- type Logger
- type Meter
- type MeterProvider
- type Observability
- type ObservabilityConfig
- type ObservabilityLogger
- type QueryOption
- type RawBuilder
- type SQLLogEntry
- type SQLLogMode
- type Session
- func (s *Session) Count(model any, opts ...QueryOption) (int64, error)
- func (s *Session) Create(model any) error
- func (s *Session) CreateMany(models any) error
- func (s *Session) Delete(model any) error
- func (s *Session) DeleteMany(models any) error
- func (s *Session) Find(dest any, opts ...QueryOption) error
- func (s *Session) FindOne(dest any, opts ...QueryOption) error
- func (s *Session) Load(dest any, relation string) error
- func (s *Session) Preload(dest any, relations ...string) error
- func (s *Session) Raw(ctx context.Context, query string, args ...any) *RawBuilder
- func (s *Session) SoftDelete(model any) error
- func (s *Session) Tx(fn func(*Session) error) error
- func (s *Session) Update(model any) error
- func (s *Session) UpdateMany(models any) error
- func (s *Session) UpdateWhere(model any, opts ...QueryOption) error
- func (s *Session) Upsert(model any) error
- func (s *Session) WithContext(ctx context.Context) *Session
- func (s *Session) WithDeleted() *Session
- func (s *Session) WithPolicy(policy access.Policy) *Session
- type Span
- type SpanOption
- type TraceSQLMode
- type Tracer
- type TracerProvider
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = dormerrors.ErrNotFound
Functions ¶
This section is empty.
Types ¶
type AfterCreateHook ¶ added in v0.1.1
type AfterDeleteHook ¶ added in v0.1.1
type AfterFindHook ¶ added in v0.1.1
type AfterUpdateHook ¶ added in v0.1.1
type BeforeCreateHook ¶ added in v0.1.1
type BeforeDeleteHook ¶ added in v0.1.1
type BeforeFindHook ¶ added in v0.1.1
type BeforeUpdateHook ¶ added in v0.1.1
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) Count ¶ added in v0.3.0
func (db *DB) Count(model any, opts ...QueryOption) (int64, error)
func (*DB) CreateMany ¶ added in v0.3.1
func (*DB) DeleteMany ¶ added in v0.3.1
func (*DB) SoftDelete ¶ added in v0.3.0
func (*DB) Transaction ¶ added in v0.3.0
func (*DB) UpdateMany ¶ added in v0.3.1
func (*DB) UpdateWhere ¶ added in v0.3.0
func (db *DB) UpdateWhere(model any, opts ...QueryOption) error
type MeterProvider ¶
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 ¶
func (c ObservabilityConfig) Normalized() ObservabilityConfig
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 RawBuilder ¶ added in v0.3.2
type RawBuilder struct {
// contains filtered or unexported fields
}
RawBuilder executes explicit SQL with an opt-in policy bypass.
func (*RawBuilder) Exec ¶ added in v0.3.2
func (r *RawBuilder) Exec() (sql.Result, error)
Exec executes a Raw SQL statement and returns the driver result.
func (*RawBuilder) Scan ¶ added in v0.3.2
func (r *RawBuilder) Scan(dest any) error
Scan executes a Raw SQL query and scans the result into a destination slice.
func (*RawBuilder) WithoutPolicy ¶ added in v0.3.2
func (r *RawBuilder) WithoutPolicy() *RawBuilder
WithoutPolicy explicitly acknowledges that Raw SQL bypasses access policy.
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) CreateMany ¶ added in v0.3.1
func (*Session) DeleteMany ¶ added in v0.3.1
func (*Session) SoftDelete ¶
func (*Session) UpdateMany ¶ added in v0.3.1
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) WithContext ¶ added in v0.1.1
func (*Session) WithDeleted ¶
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 TracerProvider ¶
TracerProvider creates named tracers.