Documentation
¶
Index ¶
- Variables
- func GetConnMaxIdleTime(maxIdleTime int) time.Duration
- func GetConnMaxLifetime(maxLifetime int) time.Duration
- func ProvideMySQL(manager Manager) *gorm.DB
- func Read() dbresolver.Operation
- func ReadDB(db *gorm.DB) *gorm.DB
- func Use(name string) clause.Expression
- func UseResolver(db *gorm.DB, resolverName string) *gorm.DB
- func UseResolverRead(db *gorm.DB, resolverName string) *gorm.DB
- func UseResolverWrite(db *gorm.DB, resolverName string) *gorm.DB
- func Write() dbresolver.Operation
- func WriteDB(db *gorm.DB) *gorm.DB
- type Database
- type GormLoggerAdapter
- func (l *GormLoggerAdapter) Error(_ context.Context, msg string, data ...interface{})
- func (l *GormLoggerAdapter) Info(_ context.Context, msg string, data ...interface{})
- func (l *GormLoggerAdapter) LogMode(level logger.LogLevel) logger.Interface
- func (l *GormLoggerAdapter) Trace(_ context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l *GormLoggerAdapter) Warn(_ context.Context, msg string, data ...interface{})
- type IDatabase
- type Manager
- type MySQLConfig
- type Options
- type SQLiteConfig
Constants ¶
This section is empty.
Variables ¶
var ProviderSet = wire.NewSet( ProvideManager, ProvideMySQL, ProvideIDatabase, )
ProviderSet provides database-related dependencies
Functions ¶
func GetConnMaxIdleTime ¶
GetConnMaxIdleTime returns ConnMaxIdleTime as time.Duration from common config
func GetConnMaxLifetime ¶
GetConnMaxLifetime returns ConnMaxLifetime as time.Duration from common config
func ProvideMySQL ¶
ProvideMySQL provides MySQL database instance from Manager
func Read ¶
func Read() dbresolver.Operation
Read forces the query to use replicas (read-only) Usage: db.Clauses(Read()).Find(&users)
func ReadDB ¶
ReadDB returns a DB instance configured for read operations (replicas) This is a convenience method for read-only queries
func Use ¶
func Use(name string) clause.Expression
Use specifies which resolver to use (for named resolvers) Usage: db.Clauses(Use("secondary")).Find(&orders)
func UseResolver ¶
UseResolver returns a DB instance configured to use a specific named resolver This is useful when you have multiple resolvers registered
func UseResolverRead ¶
UseResolverRead returns a DB instance configured to use a specific named resolver in read mode
func UseResolverWrite ¶
UseResolverWrite returns a DB instance configured to use a specific named resolver in write mode
func Write ¶
func Write() dbresolver.Operation
Write forces the query to use sources (write) Usage: db.Clauses(Write()).First(&user)
Types ¶
type Database ¶
type Database struct {
// Driver is the database driver: "mysql" or "sqlite". Defaults to "mysql" when empty.
Driver string `mapstructure:"driver"`
// Data source configurations (only the one matching driver is required)
MySQL MySQLConfig `mapstructure:"mysql"`
SQLite SQLiteConfig `mapstructure:"sqlite"`
// Common options for connection pool and logging
Options Options `mapstructure:"options"`
}
Database represents the database configuration
type GormLoggerAdapter ¶
func NewGormLoggerAdapter ¶
func NewGormLoggerAdapter(config logger.Config, logLevel logger.LogLevel) *GormLoggerAdapter
func (*GormLoggerAdapter) Error ¶
func (l *GormLoggerAdapter) Error(_ context.Context, msg string, data ...interface{})
func (*GormLoggerAdapter) Info ¶
func (l *GormLoggerAdapter) Info(_ context.Context, msg string, data ...interface{})
func (*GormLoggerAdapter) LogMode ¶
func (l *GormLoggerAdapter) LogMode(level logger.LogLevel) logger.Interface
type IDatabase ¶
type IDatabase interface {
// Database returns the default *gorm.DB (MySQL or SQLite)
Database() *gorm.DB
}
IDatabase defines database interface for backward compatibility It provides access to the default database connection (MySQL or SQLite per config)
func NewDatabaseAdapter ¶
NewDatabaseAdapter creates an IDatabase adapter from Manager
func ProvideIDatabase ¶
ProvideIDatabase provides IDatabase interface instance for backward compatibility
type Manager ¶
type Manager interface {
// MySQL returns the MySQL database connection (may be nil if using SQLite only)
MySQL() *gorm.DB
// SQLite returns the SQLite database connection (may be nil if using MySQL only)
SQLite() *gorm.DB
// Default returns the default database connection for the configured driver
Default() *gorm.DB
// Close closes all database connections
Close() error
}
Manager defines the unified database interface for managing database connections
func NewManager ¶
NewManager creates a new database manager with MySQL and/or SQLite connections
type MySQLConfig ¶
type MySQLConfig struct {
DSN string `mapstructure:"dsn"`
}
MySQLConfig represents MySQL data source configuration (DSN only)
type Options ¶
type Options struct {
OutPut bool `mapstructure:"output"`
MaxOpenConns int `mapstructure:"maxOpenConns"`
MaxIdleConns int `mapstructure:"maxIdleConns"`
MaxLifetime int `mapstructure:"maxLifeTime"`
MaxIdleTime int `mapstructure:"maxIdleTime"`
}
Options holds common connection pool and logging options
type SQLiteConfig ¶
type SQLiteConfig struct {
DSN string `mapstructure:"dsn"`
}
SQLiteConfig represents SQLite data source configuration (DSN only)