db

package
v0.0.0-...-e303333 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MySQLDefaultDns     = "root:123456@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=True&loc=Local&allowPublicKeyRetrieval=true"
	PostgresDefaultDns  = "host=localhost user=postgres password=123456 dbname=postgres port=5432 sslmode=disable TimeZone=Asia/Shanghai"
	SQLServerDefaultDsn = "sqlserver://sa:your_password@localhost:1433?database=master"
	SQLiteDefaultDsn    = "test.db"
	MaxOpenConns        = 10
	MaxIdleConns        = 5
	ConnMaxLifetime     = 10 * time.Minute
)

Variables

This section is empty.

Functions

func NewGormZapLogger

func NewGormZapLogger(l *zap.Logger, logLevel string, slowThreshold time.Duration) logger.Interface

NewGormZapLogger 构造器

func NewMysqlDB

func NewMysqlDB(lc fx.Lifecycle, opts *MySQLConfigOptions, logger *zap.Logger) (*gorm.DB, error)

NewMySQLDB

func NewPostgresDB

func NewPostgresDB(lc fx.Lifecycle, opts *PostgresConfigOptions, logger *zap.Logger) (*gorm.DB, error)

NewPostgresDB

func NewSQLServer

func NewSQLServer(lc fx.Lifecycle, opts *SQLServerConfigOptions, logger *zap.Logger) (*gorm.DB, error)

NewSQLServer

func NewSQLite

func NewSQLite(lc fx.Lifecycle, opts *SQLiteConfigOptions, logger *zap.Logger) (*gorm.DB, error)

NewSQLServer

Types

type DatabaseConfig

type DatabaseConfig struct {
	LogLevel        string        `mapstructure:"log_level"`
	SlowThreshold   time.Duration `mapstructure:"slow_threshold"`
	DryRun          bool          `mapstructure:"dry_run"`
	MaxOpenConns    int           `mapstructure:"max_open_conns"`
	MaxIdleConns    int           `mapstructure:"max_idle_conns"`
	ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"`
	*gorm.Config
}

type GormZapLogger

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

GormZapLogger 让GORM日志走zap

func (*GormZapLogger) Error

func (g *GormZapLogger) Error(ctx context.Context, msg string, data ...interface{})

func (*GormZapLogger) Info

func (g *GormZapLogger) Info(ctx context.Context, msg string, data ...interface{})

func (*GormZapLogger) LogMode

func (g *GormZapLogger) LogMode(level logger.LogLevel) logger.Interface

实现 logger.Interface 四个方法

func (*GormZapLogger) Trace

func (g *GormZapLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (*GormZapLogger) Warn

func (g *GormZapLogger) Warn(ctx context.Context, msg string, data ...interface{})

type MySQLConfigOptions

type MySQLConfigOptions struct {
	DatabaseConfig
	MySQLCfg mysql.Config
}

MySQLConfigOptions 公共字段 + 扩展字段

type PostgresConfigOptions

type PostgresConfigOptions struct {
	DatabaseConfig `mapstructure:",squash"`
	PgSQLCfg       postgres.Config
}

PostgresConfigOptions

type SQLServerConfigOptions

type SQLServerConfigOptions struct {
	DatabaseConfig
	SQLServerCfg sqlserver.Config
}

type SQLiteConfigOptions

type SQLiteConfigOptions struct {
	DatabaseConfig
	SQLiteCfg sqlite.Config
}

Jump to

Keyboard shortcuts

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