database

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GormCheck added in v1.4.0

func GormCheck(cfg Config, db *gorm.DB, log *zap.Logger) error

func Module

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

func NewGormDB

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

func NewPostgresDialector

func NewPostgresDialector(config Config) gorm.Dialector

func RunCheck added in v1.5.0

func RunCheck() di.Node

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 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 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