Documentation ¶
Index ¶
- Variables
- func Close()
- func CreateConnection(config DatabaseConfig) (db *gorm.DB, err error)
- func GetDatabase(name string) *gorm.DB
- func InitDb(connections []map[string]any)
- func Mysql(dsn string) gorm.Dialector
- func Postgres(dsn string) gorm.Dialector
- func Sqlserver(dsn string) gorm.Dialector
- type DatabaseConfig
- type Logger
- func (l Logger) Error(ctx context.Context, str string, args ...interface{})
- func (l Logger) Info(ctx context.Context, str string, args ...interface{})
- func (l Logger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
- func (l Logger) SetAsDefault()
- func (l Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l Logger) Warn(ctx context.Context, str string, args ...interface{})
Constants ¶
This section is empty.
Variables ¶
View Source
var (
Master map[string]*gorm.DB
)
Functions ¶
func CreateConnection ¶ added in v1.7.3
func CreateConnection(config DatabaseConfig) (db *gorm.DB, err error)
CreateConnection creates a single database connection based on the configuration 创建基于配置的单个数据库连接
func GetDatabase ¶ added in v1.7.3
GetDatabase retrieves a database connection by name 通过名称检索数据库连接
Types ¶
type DatabaseConfig ¶ added in v1.7.3
type DatabaseConfig struct { Name string `json:"name"` Type string `json:"type"` Hostname string `json:"hostname"` Port string `json:"port"` Username string `json:"username"` Password string `json:"password"` DatabaseName string `json:"database"` Params string `json:"params"` LogEnabled bool `json:"log"` DSN string `json:"dsn"` MaxIdleConns int `json:"max_idle_conns"` MaxOpenConns int `json:"max_open_conns"` ConnMaxLifetime int `json:"conn_max_lifetime"` ConnMaxIdleTime int `json:"conn_max_idleTime"` LogLevel gormlogger.LogLevel `json:"level"` }
func (*DatabaseConfig) Distributed ¶ added in v1.7.3
func (d *DatabaseConfig) Distributed(config dbresolver.Config, datas ...interface{}) *dbresolver.DBResolver
Distributed 分布式
type Logger ¶
type Logger struct { ZapLogger *zap.Logger LogLevel gormlogger.LogLevel SlowThreshold time.Duration SkipCallerLookup bool IgnoreRecordNotFoundError bool }
func (Logger) LogMode ¶
func (l Logger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
func (Logger) SetAsDefault ¶
func (l Logger) SetAsDefault()
Click to show internal directories.
Click to hide internal directories.