database

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMigrationsSource = errors.New("database: no migration source provided (did you forget to call UseMigrations?)")
)

Functions

func Module

func Module(opts ...di.Node) di.Node

func NewDialector added in v1.12.0

func NewDialector(config Config) gorm.Dialector

func NewGooseZapLogger added in v1.12.0

func NewGooseZapLogger(logger *zap.Logger) goose.Logger

NewGooseZapLogger adapts zap.Logger to goose.Logger.

func NewGormDB

func NewGormDB(dialecter gorm.Dialector) (*gorm.DB, error)

func NewPostgresDialector

func NewPostgresDialector(config Config) gorm.Dialector

NewPostgresDialector is kept for backward compatibility.

func ParseDialect added in v1.12.0

func ParseDialect(d string) string

func RunMigrations added in v1.5.0

func RunMigrations() di.Node

RunMigrations runs goose migrations using the source registered by UseMigrations.

func UseMigrations

func UseMigrations(migrationsDirFS *embed.FS, paths ...string) di.Node

UseMigrations registers migration files in the DI container.

func UseOtel added in v1.4.0

func UseOtel() di.Node

Types

type Config

type Config struct {
	Dialect    string      `mapstructure:"dialect"`
	Migrate    bool        `mapstructure:"migrate"`
	Datasource string      `mapstructure:"datasource"`
	Log        LogConfig   `mapstructure:"log"`
	Trace      TraceConfig `mapstructure:"trace"`
}

type ContextFn

type ContextFn func(ctx context.Context) []zapcore.Field

type GormChecker added in v1.12.0

type GormChecker struct {
	otel.Telemetry
	// contains filtered or unexported fields
}

func NewGormChecker added in v1.12.0

func NewGormChecker(cfg Config, db *gorm.DB) *GormChecker

func (*GormChecker) Check added in v1.12.0

func (g *GormChecker) Check() error

type GormOtel added in v1.4.0

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

func NewGormOtel added in v1.4.0

func NewGormOtel(dbConfig Config, otelConfig otel.Config, db *gorm.DB, logger *zap.Logger, tp *otel.TracerProvider) *GormOtel

type LogConfig added in v1.4.0

type LogConfig struct {
	Enabled                   *bool         `mapstructure:"enabled"`
	LogLevel                  string        `mapstructure:"level" default:"warn"`
	SlowThreshold             time.Duration `mapstructure:"slow_threshold" default:"100ms"`
	SkipCallerLookup          bool          `mapstructure:"skip_caller_lookup" default:"false"`
	IgnoreRecordNotFoundError bool          `mapstructure:"ignore_record_not_found_error" default:"false"`
	ParameterizedQueries      bool          `mapstructure:"parameterized_queries" default:"true"`
}

type Logger

type Logger struct {
	ZapLogger                 *zap.Logger
	LogLevel                  gormlogger.LogLevel
	SlowThreshold             time.Duration
	SkipCallerLookup          bool
	IgnoreRecordNotFoundError bool
	Context                   ContextFn
	ParameterizedQueries      bool
}

func NewGormLogger

func NewGormLogger(zapLogger *zap.Logger, opts ...Option) Logger

func (Logger) Error

func (l Logger) Error(ctx context.Context, str string, args ...any)

func (Logger) Info

func (l Logger) Info(ctx context.Context, str string, args ...any)

func (Logger) LogMode

func (l Logger) LogMode(level gormlogger.LogLevel) gormlogger.Interface

func (Logger) ParamsFilter

func (l Logger) ParamsFilter(ctx context.Context, sql string, params ...any) (string, []any)

func (Logger) SetAsDefault

func (l Logger) SetAsDefault()

func (Logger) Trace

func (l Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (Logger) Warn

func (l Logger) Warn(ctx context.Context, str string, args ...any)

type Migration added in v1.12.0

type Migration struct {
	FS    *embed.FS
	Paths []string
	// contains filtered or unexported fields
}

func NewMigration added in v1.12.0

func NewMigration(
	fs *embed.FS,
	config Config,
	db *gorm.DB,
	logger *zap.Logger,
	paths ...string,
) *Migration

func (*Migration) Run added in v1.12.0

func (m *Migration) Run() error

type Option

type Option func(*Logger)

func WithParamFilter

func WithParamFilter(on bool) Option

type TraceConfig added in v1.4.0

type TraceConfig struct {
	Enabled               *bool             `mapstructure:"enabled"`
	DBName                string            `mapstructure:"db_name"`
	Attributes            map[string]string `mapstructure:"attributes"`
	WithoutQueryVariables bool              `mapstructure:"without_query_variables" default:"true"`
	WithoutMetrics        bool              `mapstructure:"without_metrics" default:"false"`
	IncludeDryRunSpans    bool              `mapstructure:"include_dry_run_spans" default:"false"`
}

Jump to

Keyboard shortcuts

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