db

package
v0.0.0-...-2af4b48 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: AGPL-3.0, AGPL-3.0-only Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DatabaseDriverMySQL = "mysql"
View Source
const DatabaseDriverPostgres = "postgres"
View Source
const DatabaseDriverSQLite = "sqlite"

Variables

This section is empty.

Functions

func GormConfig

func GormConfig(logger *zap.Logger) *gorm.Config

func InitDB

func InitDB(cfg DatabaseConfig, logger *zap.Logger) (*gorm.DB, error)

Types

type DatabaseConfig

type DatabaseConfig struct {
	Driver string `mapstructure:"driver"`
	Path   string `mapstructure:"path"`
	DSN    string `mapstructure:"dsn"`
}

func (DatabaseConfig) GormDialector

func (c DatabaseConfig) GormDialector() (gorm.Dialector, error)

func (DatabaseConfig) ResolvedDriver

func (c DatabaseConfig) ResolvedDriver() (string, error)

func (DatabaseConfig) RuntimeDSN

func (c DatabaseConfig) RuntimeDSN() (string, error)

func (DatabaseConfig) SQLDriverName

func (c DatabaseConfig) SQLDriverName() (string, error)

SQLDriverName returns the driver name to be used with sql.Open for the given database configuration.

type Logger

type Logger struct {
	ZapLogger                 *zap.Logger
	LogLevel                  gormlogger.LogLevel
	SlowThreshold             time.Duration
	SkipCallerLookup          bool
	IgnoreRecordNotFoundError bool
	PrintQuery                bool // When true, print the query to the console (without escapes)
}

func NewZapLogger

func NewZapLogger(zapLogger *zap.Logger, logLevel int) Logger

func (Logger) Error

func (l Logger) Error(ctx context.Context, str string, args ...interface{})

func (Logger) Info

func (l Logger) Info(ctx context.Context, str string, args ...interface{})

func (Logger) LogMode

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

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 ...interface{})

Jump to

Keyboard shortcuts

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