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) Close() error
- func (db *DB) Dialect() dialect.Dialect
- func (db *DB) Ping(ctx context.Context) error
- func (db *DB) PingContext(ctx context.Context) error
- func (db *DB) SQLDB() *sql.DB
- func (db *DB) Stats() sql.DBStats
- func (db *DB) Tx(ctx context.Context, fn func(*Session) error) 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 ObservabilityConfig
- type ObservabilityLogger
- type QueryOption
- 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) Delete(model 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) SoftDelete(model any) error
- func (s *Session) Tx(fn func(*Session) error) error
- func (s *Session) Update(model 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 Tracer
- type TracerProvider
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("orm: not found")
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 MeterProvider ¶
MeterProvider creates named meters.
type ObservabilityConfig ¶
type ObservabilityConfig struct {
Tracing bool
Metrics bool
SQLLogging SQLLogMode
SlowQueryThreshold time.Duration
MaskParameters bool
MaskedFields []string
Logger ObservabilityLogger
TracerProvider TracerProvider
MeterProvider MeterProvider
}
ObservabilityConfig configures tracing, metrics, and SQL logging.
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 SQLLogEntry ¶
type SQLLogEntry struct {
SQL string
Args []any
Duration time.Duration
AffectedRows int64
Timestamp time.Time
Err error
Slow bool
}
SQLLogEntry captures a single SQL log event.
type SQLLogMode ¶
type SQLLogMode string
SQLLogMode controls how SQL statements are reported.
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) SoftDelete ¶
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 TracerProvider ¶
TracerProvider creates named tracers.