orm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	Key   string
	Value any
}

type Config

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

type Counter

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

type DB

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

func New

func New(cfg Config) *DB

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

type Histogram

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

type Logger

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

type Meter

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

type MeterProvider

type MeterProvider interface {
	Meter(name string) Meter
}

type ObservabilityConfig

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

func DefaultObservabilityConfig

func DefaultObservabilityConfig() ObservabilityConfig

func (ObservabilityConfig) Enabled

func (c ObservabilityConfig) Enabled() bool

func (ObservabilityConfig) Normalized

func (ObservabilityConfig) ShouldMask

func (c ObservabilityConfig) ShouldMask(field string) bool

func (ObservabilityConfig) Validate

func (c ObservabilityConfig) Validate() error

type ObservabilityLogger

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

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
}

type SQLLogMode

type SQLLogMode string
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) 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) 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) Upsert

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

func (*Session) WithDeleted

func (s *Session) WithDeleted() *Session

type Span

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

type SpanOption

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

type Tracer

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

type TracerProvider

type TracerProvider interface {
	Tracer(name string) Tracer
}

Jump to

Keyboard shortcuts

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