Documentation
¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2024-11-03 20:55:05 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-04-28 11:16:58 * @FilePath: \go-config\pkg\database\cockroachdb.go * @Description: CockroachDB统一配置管理 * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2024-11-03 20:55:05 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-12 22:50:17 * @FilePath: \go-config\pkg\database\database.go * @Description: 数据库统一配置管理 * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-12 23:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-22 16:54:04 * @FilePath: \go-config\pkg\database\mysql.go * @Description: MySQL数据库配置 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-12 23:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-22 16:53:36 * @FilePath: \go-config\pkg\database\postgresql.go * @Description: PostgreSQL数据库配置 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-12 23:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-16 19:03:40 * @FilePath: \go-config\pkg\database\sqlite.go * @Description: SQLite数据库配置 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
Index ¶
- func GetProviderName(dbType DBType) string
- type CockroachDB
- func (c *CockroachDB) Clone() internal.Configurable
- func (c *CockroachDB) Get() interface{}
- func (c *CockroachDB) GetAllowGlobalUpdate() bool
- func (c *CockroachDB) GetConfig() string
- func (c *CockroachDB) GetCreateBatchSize() int
- func (c *CockroachDB) GetDBName() string
- func (c *CockroachDB) GetDBType() DBType
- func (c *CockroachDB) GetDisableForeignKeyConstraintWhenMigrating() bool
- func (c *CockroachDB) GetDisableNestedTransaction() bool
- func (c *CockroachDB) GetHost() string
- func (c *CockroachDB) GetIgnoreRecordNotFoundError() bool
- func (c *CockroachDB) GetLogLevel() string
- func (c *CockroachDB) GetModuleName() string
- func (c *CockroachDB) GetPassword() string
- func (c *CockroachDB) GetPort() string
- func (c *CockroachDB) GetPrepareStmt() bool
- func (c *CockroachDB) GetQueryFields() bool
- func (c *CockroachDB) GetSingularTable() bool
- func (c *CockroachDB) GetSkipDefaultTransaction() bool
- func (c *CockroachDB) GetSlowThreshold() int
- func (c *CockroachDB) GetUsername() string
- func (c *CockroachDB) Set(data interface{})
- func (c *CockroachDB) SetCredentials(username, password string)
- func (c *CockroachDB) SetDBName(dbName string)
- func (c *CockroachDB) SetHost(host string)
- func (c *CockroachDB) SetPort(port string)
- func (c *CockroachDB) Validate() error
- func (c *CockroachDB) WithConfig(config string) *CockroachDB
- func (c *CockroachDB) WithConnMaxIdleTime(connMaxIdleTime int) *CockroachDB
- func (c *CockroachDB) WithConnMaxLifeTime(connMaxLifeTime int) *CockroachDB
- func (c *CockroachDB) WithDbname(dbname string) *CockroachDB
- func (c *CockroachDB) WithHost(host string) *CockroachDB
- func (c *CockroachDB) WithLogLevel(logLevel string) *CockroachDB
- func (c *CockroachDB) WithMaxIdleConns(maxIdleConns int) *CockroachDB
- func (c *CockroachDB) WithMaxOpenConns(maxOpenConns int) *CockroachDB
- func (c *CockroachDB) WithModuleName(moduleName string) *CockroachDB
- func (c *CockroachDB) WithPassword(password string) *CockroachDB
- func (c *CockroachDB) WithPort(port string) *CockroachDB
- func (c *CockroachDB) WithUsername(username string) *CockroachDB
- type DBType
- type Database
- func (c *Database) AfterLoad() error
- func (c *Database) BeforeLoad() error
- func (c *Database) Clone() internal.Configurable
- func (d *Database) EnableCockroachDB() *Database
- func (d *Database) EnableDatabase() *Database
- func (d *Database) EnableMySQL() *Database
- func (d *Database) EnablePostgreSQL() *Database
- func (d *Database) EnableSQLite() *Database
- func (c *Database) EnsureDefaults()
- func (c *Database) Get() interface{}
- func (c *Database) GetDefaultProvider() (DatabaseProvider, error)
- func (c *Database) GetProvider(dbType DBType) (DatabaseProvider, error)
- func (c *Database) GetSafe() interface{}
- func (c *Database) ListAvailableProviders() []DBType
- func (c *Database) Set(data interface{})
- func (c *Database) SetDefaultProvider(dbType DBType)
- func (c *Database) Validate() error
- func (c *Database) ValidateAll() error
- func (c *Database) ValidateProvider(dbType DBType) error
- func (d *Database) WithCockroachDB(cockroachdb *CockroachDB) *Database
- func (d *Database) WithDefault(defaultDB string) *Database
- func (d *Database) WithEnabled(enabled bool) *Database
- func (d *Database) WithMySQL(mysql *MySQL) *Database
- func (d *Database) WithPostgreSQL(postgresql *PostgreSQL) *Database
- func (d *Database) WithSQLite(sqlite *SQLite) *Database
- func (d *Database) WithType(dbType DBType) *Database
- type DatabaseProvider
- type MySQL
- func (m *MySQL) Clone() internal.Configurable
- func (m *MySQL) Get() interface{}
- func (m *MySQL) GetAllowGlobalUpdate() bool
- func (m *MySQL) GetConfig() string
- func (m *MySQL) GetCreateBatchSize() int
- func (m *MySQL) GetDBName() string
- func (m *MySQL) GetDBType() DBType
- func (m *MySQL) GetDisableForeignKeyConstraintWhenMigrating() bool
- func (m *MySQL) GetDisableNestedTransaction() bool
- func (m *MySQL) GetHost() string
- func (m *MySQL) GetIgnoreRecordNotFoundError() bool
- func (m *MySQL) GetLogLevel() string
- func (m *MySQL) GetModuleName() string
- func (m *MySQL) GetPassword() string
- func (m *MySQL) GetPort() string
- func (m *MySQL) GetPrepareStmt() bool
- func (m *MySQL) GetQueryFields() bool
- func (m *MySQL) GetSingularTable() bool
- func (m *MySQL) GetSkipDefaultTransaction() bool
- func (m *MySQL) GetSlowThreshold() int
- func (m *MySQL) GetUsername() string
- func (m *MySQL) Set(data interface{})
- func (m *MySQL) SetCredentials(username, password string)
- func (m *MySQL) SetDBName(dbName string)
- func (m *MySQL) SetHost(host string)
- func (m *MySQL) SetPort(port string)
- func (m *MySQL) Validate() error
- func (m *MySQL) WithConfig(config string) *MySQL
- func (m *MySQL) WithConnMaxIdleTime(connMaxIdleTime int) *MySQL
- func (m *MySQL) WithConnMaxLifeTime(connMaxLifeTime int) *MySQL
- func (m *MySQL) WithDbname(dbname string) *MySQL
- func (m *MySQL) WithHost(host string) *MySQL
- func (m *MySQL) WithLogLevel(logLevel string) *MySQL
- func (m *MySQL) WithMaxIdleConns(maxIdleConns int) *MySQL
- func (m *MySQL) WithMaxOpenConns(maxOpenConns int) *MySQL
- func (m *MySQL) WithModuleName(moduleName string) *MySQL
- func (m *MySQL) WithPassword(password string) *MySQL
- func (m *MySQL) WithPort(port string) *MySQL
- func (m *MySQL) WithUsername(username string) *MySQL
- type PostgreSQL
- func (p *PostgreSQL) Clone() internal.Configurable
- func (p *PostgreSQL) Get() interface{}
- func (p *PostgreSQL) GetAllowGlobalUpdate() bool
- func (p *PostgreSQL) GetConfig() string
- func (p *PostgreSQL) GetCreateBatchSize() int
- func (p *PostgreSQL) GetDBName() string
- func (p *PostgreSQL) GetDBType() DBType
- func (p *PostgreSQL) GetDisableForeignKeyConstraintWhenMigrating() bool
- func (p *PostgreSQL) GetDisableNestedTransaction() bool
- func (p *PostgreSQL) GetHost() string
- func (p *PostgreSQL) GetIgnoreRecordNotFoundError() bool
- func (p *PostgreSQL) GetLogLevel() string
- func (p *PostgreSQL) GetModuleName() string
- func (p *PostgreSQL) GetPassword() string
- func (p *PostgreSQL) GetPort() string
- func (p *PostgreSQL) GetPrepareStmt() bool
- func (p *PostgreSQL) GetQueryFields() bool
- func (p *PostgreSQL) GetSingularTable() bool
- func (p *PostgreSQL) GetSkipDefaultTransaction() bool
- func (p *PostgreSQL) GetSlowThreshold() int
- func (p *PostgreSQL) GetUsername() string
- func (p *PostgreSQL) Set(data interface{})
- func (p *PostgreSQL) SetCredentials(username, password string)
- func (p *PostgreSQL) SetDBName(dbName string)
- func (p *PostgreSQL) SetHost(host string)
- func (p *PostgreSQL) SetPort(port string)
- func (p *PostgreSQL) Validate() error
- func (p *PostgreSQL) WithConfig(config string) *PostgreSQL
- func (p *PostgreSQL) WithConnMaxIdleTime(connMaxIdleTime int) *PostgreSQL
- func (p *PostgreSQL) WithConnMaxLifeTime(connMaxLifeTime int) *PostgreSQL
- func (p *PostgreSQL) WithDbname(dbname string) *PostgreSQL
- func (p *PostgreSQL) WithHost(host string) *PostgreSQL
- func (p *PostgreSQL) WithLogLevel(logLevel string) *PostgreSQL
- func (p *PostgreSQL) WithMaxIdleConns(maxIdleConns int) *PostgreSQL
- func (p *PostgreSQL) WithMaxOpenConns(maxOpenConns int) *PostgreSQL
- func (p *PostgreSQL) WithModuleName(moduleName string) *PostgreSQL
- func (p *PostgreSQL) WithPassword(password string) *PostgreSQL
- func (p *PostgreSQL) WithPort(port string) *PostgreSQL
- func (p *PostgreSQL) WithUsername(username string) *PostgreSQL
- type SQLite
- func (s *SQLite) Clone() internal.Configurable
- func (s *SQLite) Get() interface{}
- func (s *SQLite) GetAllowGlobalUpdate() bool
- func (s *SQLite) GetConfig() string
- func (s *SQLite) GetCreateBatchSize() int
- func (s *SQLite) GetDBName() string
- func (s *SQLite) GetDBType() DBType
- func (s *SQLite) GetDisableForeignKeyConstraintWhenMigrating() bool
- func (s *SQLite) GetDisableNestedTransaction() bool
- func (s *SQLite) GetHost() string
- func (s *SQLite) GetIgnoreRecordNotFoundError() bool
- func (s *SQLite) GetLogLevel() string
- func (s *SQLite) GetModuleName() string
- func (s *SQLite) GetPassword() string
- func (s *SQLite) GetPort() string
- func (s *SQLite) GetPrepareStmt() bool
- func (s *SQLite) GetQueryFields() bool
- func (s *SQLite) GetSingularTable() bool
- func (s *SQLite) GetSkipDefaultTransaction() bool
- func (s *SQLite) GetSlowThreshold() int
- func (s *SQLite) GetUsername() string
- func (s *SQLite) Set(data interface{})
- func (s *SQLite) SetCredentials(username, password string)
- func (s *SQLite) SetDBName(dbName string)
- func (s *SQLite) SetHost(host string)
- func (s *SQLite) SetPort(port string)
- func (s *SQLite) Validate() error
- func (s *SQLite) WithConfig(config string) *SQLite
- func (s *SQLite) WithConnMaxIdleTime(connMaxIdleTime int) *SQLite
- func (s *SQLite) WithConnMaxLifeTime(connMaxLifeTime int) *SQLite
- func (s *SQLite) WithDbPath(dbPath string) *SQLite
- func (s *SQLite) WithLogLevel(logLevel string) *SQLite
- func (s *SQLite) WithMaxIdleConns(maxIdleConns int) *SQLite
- func (s *SQLite) WithMaxOpenConns(maxOpenConns int) *SQLite
- func (s *SQLite) WithModuleName(moduleName string) *SQLite
- func (s *SQLite) WithVacuum(vacuum bool) *SQLite
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CockroachDB ¶
type CockroachDB struct {
ModuleName string `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`
Host string `mapstructure:"host" yaml:"host" json:"host" validate:"required"`
Port string `mapstructure:"port" yaml:"port" json:"port" validate:"required"`
Config string `mapstructure:"config" yaml:"config" json:"config" validate:"required"`
LogLevel string `mapstructure:"log-level" yaml:"log-level" json:"logLevel" validate:"required"`
SlowThreshold int `mapstructure:"slow-threshold" yaml:"slow-threshold" json:"slowThreshold"`
IgnoreRecordNotFoundError bool `mapstructure:"ignore-record-not-found-error" yaml:"ignore-record-not-found-error" json:"ignoreRecordNotFoundError"`
Dbname string `mapstructure:"db-name" yaml:"db-name" json:"dbName" validate:"required"`
Username string `mapstructure:"username" yaml:"username" json:"username" validate:"required"`
Password string `mapstructure:"password" yaml:"password" json:"password" validate:"required"`
MaxIdleConns int `mapstructure:"max-idle-conns" yaml:"max-idle-conns" json:"maxIdleConns" validate:"min=0"`
MaxOpenConns int `mapstructure:"max-open-conns" yaml:"max-open-conns" json:"maxOpenConns" validate:"min=0"`
ConnMaxIdleTime int `mapstructure:"conn-max-idle-time" yaml:"conn-max-idle-time" json:"connMaxIdleTime" validate:"min=0"`
ConnMaxLifeTime int `mapstructure:"conn-max-life-time" yaml:"conn-max-life-time" json:"connMaxLifeTime" validate:"min=0"`
SkipDefaultTransaction bool `mapstructure:"skip-default-transaction" yaml:"skip-default-transaction" json:"skipDefaultTransaction"`
PrepareStmt bool `mapstructure:"prepare-stmt" yaml:"prepare-stmt" json:"prepareStmt"`
DisableForeignKeyConstraintWhenMigrating bool `` /* 161-byte string literal not displayed */
DisableNestedTransaction bool `mapstructure:"disable-nested-transaction" yaml:"disable-nested-transaction" json:"disableNestedTransaction"`
AllowGlobalUpdate bool `mapstructure:"allow-global-update" yaml:"allow-global-update" json:"allowGlobalUpdate"`
QueryFields bool `mapstructure:"query-fields" yaml:"query-fields" json:"queryFields"`
CreateBatchSize int `mapstructure:"create-batch-size" yaml:"create-batch-size" json:"createBatchSize"`
SingularTable bool `mapstructure:"singular-table" yaml:"singular-table" json:"singularTable"`
}
func DefaultCockroachDB ¶
func DefaultCockroachDB() *CockroachDB
func NewCockroachDBConfig ¶
func NewCockroachDBConfig(opt *CockroachDB) *CockroachDB
func (*CockroachDB) Clone ¶
func (c *CockroachDB) Clone() internal.Configurable
func (*CockroachDB) Get ¶
func (c *CockroachDB) Get() interface{}
func (*CockroachDB) GetAllowGlobalUpdate ¶
func (c *CockroachDB) GetAllowGlobalUpdate() bool
func (*CockroachDB) GetConfig ¶
func (c *CockroachDB) GetConfig() string
func (*CockroachDB) GetCreateBatchSize ¶
func (c *CockroachDB) GetCreateBatchSize() int
func (*CockroachDB) GetDBName ¶
func (c *CockroachDB) GetDBName() string
func (*CockroachDB) GetDBType ¶
func (c *CockroachDB) GetDBType() DBType
func (*CockroachDB) GetDisableForeignKeyConstraintWhenMigrating ¶
func (c *CockroachDB) GetDisableForeignKeyConstraintWhenMigrating() bool
func (*CockroachDB) GetDisableNestedTransaction ¶
func (c *CockroachDB) GetDisableNestedTransaction() bool
func (*CockroachDB) GetHost ¶
func (c *CockroachDB) GetHost() string
func (*CockroachDB) GetIgnoreRecordNotFoundError ¶
func (c *CockroachDB) GetIgnoreRecordNotFoundError() bool
func (*CockroachDB) GetLogLevel ¶
func (c *CockroachDB) GetLogLevel() string
func (*CockroachDB) GetModuleName ¶
func (c *CockroachDB) GetModuleName() string
func (*CockroachDB) GetPassword ¶
func (c *CockroachDB) GetPassword() string
func (*CockroachDB) GetPort ¶
func (c *CockroachDB) GetPort() string
func (*CockroachDB) GetPrepareStmt ¶
func (c *CockroachDB) GetPrepareStmt() bool
func (*CockroachDB) GetQueryFields ¶
func (c *CockroachDB) GetQueryFields() bool
func (*CockroachDB) GetSingularTable ¶
func (c *CockroachDB) GetSingularTable() bool
func (*CockroachDB) GetSkipDefaultTransaction ¶
func (c *CockroachDB) GetSkipDefaultTransaction() bool
func (*CockroachDB) GetSlowThreshold ¶
func (c *CockroachDB) GetSlowThreshold() int
func (*CockroachDB) GetUsername ¶
func (c *CockroachDB) GetUsername() string
func (*CockroachDB) Set ¶
func (c *CockroachDB) Set(data interface{})
func (*CockroachDB) SetCredentials ¶
func (c *CockroachDB) SetCredentials(username, password string)
func (*CockroachDB) SetDBName ¶
func (c *CockroachDB) SetDBName(dbName string)
func (*CockroachDB) SetHost ¶
func (c *CockroachDB) SetHost(host string)
func (*CockroachDB) SetPort ¶
func (c *CockroachDB) SetPort(port string)
func (*CockroachDB) Validate ¶
func (c *CockroachDB) Validate() error
func (*CockroachDB) WithConfig ¶
func (c *CockroachDB) WithConfig(config string) *CockroachDB
func (*CockroachDB) WithConnMaxIdleTime ¶
func (c *CockroachDB) WithConnMaxIdleTime(connMaxIdleTime int) *CockroachDB
func (*CockroachDB) WithConnMaxLifeTime ¶
func (c *CockroachDB) WithConnMaxLifeTime(connMaxLifeTime int) *CockroachDB
func (*CockroachDB) WithDbname ¶
func (c *CockroachDB) WithDbname(dbname string) *CockroachDB
func (*CockroachDB) WithHost ¶
func (c *CockroachDB) WithHost(host string) *CockroachDB
func (*CockroachDB) WithLogLevel ¶
func (c *CockroachDB) WithLogLevel(logLevel string) *CockroachDB
func (*CockroachDB) WithMaxIdleConns ¶
func (c *CockroachDB) WithMaxIdleConns(maxIdleConns int) *CockroachDB
func (*CockroachDB) WithMaxOpenConns ¶
func (c *CockroachDB) WithMaxOpenConns(maxOpenConns int) *CockroachDB
func (*CockroachDB) WithModuleName ¶
func (c *CockroachDB) WithModuleName(moduleName string) *CockroachDB
func (*CockroachDB) WithPassword ¶
func (c *CockroachDB) WithPassword(password string) *CockroachDB
func (*CockroachDB) WithPort ¶
func (c *CockroachDB) WithPort(port string) *CockroachDB
func (*CockroachDB) WithUsername ¶
func (c *CockroachDB) WithUsername(username string) *CockroachDB
type Database ¶
type Database struct {
Type DBType `mapstructure:"type" yaml:"type" json:"type"` // 数据库类型
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"` // 是否启用
Default string `mapstructure:"default" yaml:"default" json:"default"` // 默认使用的数据库
MySQL *MySQL `mapstructure:"mysql" yaml:"mysql" json:"mysql"` // MySQL配置
PostgreSQL *PostgreSQL `mapstructure:"postgresql" yaml:"postgresql" json:"postgresql"` // PostgreSQL配置
SQLite *SQLite `mapstructure:"sqlite" yaml:"sqlite" json:"sqlite"` // SQLite配置
CockroachDB *CockroachDB `mapstructure:"cockroachdb" yaml:"cockroachdb" json:"cockroachdb"` // CockroachDB配置
}
Database 数据库统一配置结构
func DefaultDatabaseConfig ¶
func DefaultDatabaseConfig() *Database
DefaultDatabaseConfig 返回默认的数据库配置
func (*Database) EnableCockroachDB ¶
EnableCockroachDB 启用CockroachDB并设置默认配置
func (*Database) EnableDatabase ¶
EnableDatabase 启用数据库
func (*Database) EnableMySQL ¶
EnableMySQL 启用MySQL并设置默认配置
func (*Database) EnablePostgreSQL ¶
EnablePostgreSQL 启用PostgreSQL并设置默认配置
func (*Database) EnableSQLite ¶
EnableSQLite 启用SQLite并设置默认配置
func (*Database) EnsureDefaults ¶
func (c *Database) EnsureDefaults()
EnsureDefaults 确保所有子配置都有默认值,避免空指针
func (*Database) GetDefaultProvider ¶
func (c *Database) GetDefaultProvider() (DatabaseProvider, error)
GetDefaultProvider 获取默认的数据库提供商
func (*Database) GetProvider ¶
func (c *Database) GetProvider(dbType DBType) (DatabaseProvider, error)
GetProvider 获取指定类型的数据库提供商
func (*Database) ListAvailableProviders ¶
ListAvailableProviders 列出所有可用的数据库提供商
func (*Database) SetDefaultProvider ¶
SetDefaultProvider 设置默认数据库提供商
func (*Database) ValidateProvider ¶
ValidateProvider 验证指定提供商的配置
func (*Database) WithCockroachDB ¶
func (d *Database) WithCockroachDB(cockroachdb *CockroachDB) *Database
WithCockroachDB 设置CockroachDB配置
func (*Database) WithDefault ¶
WithDefault 设置默认数据库
func (*Database) WithEnabled ¶
WithEnabled 设置是否启用数据库
func (*Database) WithPostgreSQL ¶
func (d *Database) WithPostgreSQL(postgresql *PostgreSQL) *Database
WithPostgreSQL 设置PostgreSQL配置
func (*Database) WithSQLite ¶
WithSQLite 设置SQLite配置
type DatabaseProvider ¶
type DatabaseProvider interface {
internal.Configurable
// GetDBType 获取数据库类型
GetDBType() DBType
// GetHost 获取主机地址
GetHost() string
// GetPort 获取端口
GetPort() string
// GetDBName 获取数据库名称
GetDBName() string
// GetUsername 获取用户名
GetUsername() string
// GetPassword 获取密码
GetPassword() string
// GetConfig 获取额外配置
GetConfig() string
// GetModuleName 获取模块名称
GetModuleName() string
// GetSlowThreshold 获取慢查询阈值(毫秒)
GetSlowThreshold() int
// GetLogLevel 获取SQL日志等级(silent/error/warn/info,gorm logger 消费)
GetLogLevel() string
// GetIgnoreRecordNotFoundError 获取是否忽略RecordNotFound错误
GetIgnoreRecordNotFoundError() bool
// GORM 性能配置 Getter 方法
// GetSkipDefaultTransaction 获取是否跳过默认事务
GetSkipDefaultTransaction() bool
// GetPrepareStmt 获取是否启用预编译语句
GetPrepareStmt() bool
// GetDisableForeignKeyConstraintWhenMigrating 获取迁移时是否禁用外键约束
GetDisableForeignKeyConstraintWhenMigrating() bool
// GetDisableNestedTransaction 获取是否禁用嵌套事务
GetDisableNestedTransaction() bool
// GetAllowGlobalUpdate 获取是否允许全局更新
GetAllowGlobalUpdate() bool
// GetQueryFields 获取是否在查询时选择所有字段
GetQueryFields() bool
// GetCreateBatchSize 获取批量创建的大小
GetCreateBatchSize() int
// GetSingularTable 获取是否使用单数表名
GetSingularTable() bool
// SetCredentials 设置凭证
SetCredentials(username, password string)
// SetHost 设置主机地址
SetHost(host string)
// SetPort 设置端口
SetPort(port string)
// SetDBName 设置数据库名称
SetDBName(dbName string)
}
DatabaseProvider 数据库提供商接口,统一不同数据库的操作
type MySQL ¶
type MySQL struct {
ModuleName string `mapstructure:"module-name" yaml:"module-name" json:"moduleName"` // 模块名称
Host string `mapstructure:"host" yaml:"host" json:"host" validate:"required"` // 数据库 IP 地址
Port string `mapstructure:"port" yaml:"port" json:"port" validate:"required"` // 端口
Config string `mapstructure:"config" yaml:"config" json:"config" validate:"required"` // 后缀配置 默认配置 charset=utf8mb4&parseTime=True&loc=Local
LogLevel string `mapstructure:"log-level" yaml:"log-level" json:"logLevel" validate:"required"` // SQL 日志等级
SlowThreshold int `mapstructure:"slow-threshold" yaml:"slow-threshold" json:"slowThreshold"` // 慢查询阈值(毫秒)
IgnoreRecordNotFoundError bool `mapstructure:"ignore-record-not-found-error" yaml:"ignore-record-not-found-error" json:"ignoreRecordNotFoundError"` // 是否忽略ErrRecordNotFound错误
Dbname string `mapstructure:"db-name" yaml:"db-name" json:"dbName" validate:"required"` // 数据库名称
Username string `mapstructure:"username" yaml:"username" json:"username" validate:"required"` // 数据库用户名
Password string `mapstructure:"password" yaml:"password" json:"password" validate:"required"` // 数据库密码
MaxIdleConns int `mapstructure:"max-idle-conns" yaml:"max-idle-conns" json:"maxIdleConns" validate:"min=0"` // 最大空闲连接数
MaxOpenConns int `mapstructure:"max-open-conns" yaml:"max-open-conns" json:"maxOpenConns" validate:"min=0"` // 最大连接数
ConnMaxIdleTime int `mapstructure:"conn-max-idle-time" yaml:"conn-max-idle-time" json:"connMaxIdleTime" validate:"min=0"` // 连接最大空闲时间 单位:秒
ConnMaxLifeTime int `mapstructure:"conn-max-life-time" yaml:"conn-max-life-time" json:"connMaxLifeTime" validate:"min=0"` // 连接最大生命周期 单位:秒
SkipDefaultTransaction bool `mapstructure:"skip-default-transaction" yaml:"skip-default-transaction" json:"skipDefaultTransaction"` // 跳过默认事务
PrepareStmt bool `mapstructure:"prepare-stmt" yaml:"prepare-stmt" json:"prepareStmt"` // 预编译语句
DisableForeignKeyConstraintWhenMigrating bool `` // 禁用自动创建外键约束
/* 161-byte string literal not displayed */
DisableNestedTransaction bool `mapstructure:"disable-nested-transaction" yaml:"disable-nested-transaction" json:"disableNestedTransaction"` // 禁用嵌套事务
AllowGlobalUpdate bool `mapstructure:"allow-global-update" yaml:"allow-global-update" json:"allowGlobalUpdate"` // 允许全局更新
QueryFields bool `mapstructure:"query-fields" yaml:"query-fields" json:"queryFields"` // 执行查询时选择所有字段
CreateBatchSize int `mapstructure:"create-batch-size" yaml:"create-batch-size" json:"createBatchSize"` // 批量创建大小
SingularTable bool `mapstructure:"singular-table" yaml:"singular-table" json:"singularTable"` // 使用单数表名
}
MySQL MySQL数据库配置
func (*MySQL) Clone ¶
func (m *MySQL) Clone() internal.Configurable
func (*MySQL) GetAllowGlobalUpdate ¶
func (*MySQL) GetCreateBatchSize ¶
func (*MySQL) GetDisableForeignKeyConstraintWhenMigrating ¶
func (*MySQL) GetDisableNestedTransaction ¶
func (*MySQL) GetIgnoreRecordNotFoundError ¶
func (*MySQL) GetLogLevel ¶
func (*MySQL) GetModuleName ¶
func (*MySQL) GetPassword ¶
func (*MySQL) GetPrepareStmt ¶
func (*MySQL) GetQueryFields ¶
func (*MySQL) GetSingularTable ¶
func (*MySQL) GetSkipDefaultTransaction ¶
func (*MySQL) GetSlowThreshold ¶
func (*MySQL) GetUsername ¶
func (*MySQL) SetCredentials ¶
func (*MySQL) WithConnMaxIdleTime ¶
WithConnMaxIdleTime 设置连接最大空闲时间
func (*MySQL) WithConnMaxLifeTime ¶
WithConnMaxLifeTime 设置连接最大生命周期
func (*MySQL) WithLogLevel ¶
WithLogLevel 设置日志级别
func (*MySQL) WithMaxIdleConns ¶
WithMaxIdleConns 设置最大空闲连接数
func (*MySQL) WithMaxOpenConns ¶
WithMaxOpenConns 设置最大连接数
func (*MySQL) WithModuleName ¶
WithModuleName 设置模块名称
func (*MySQL) WithPassword ¶
WithPassword 设置数据库密码
func (*MySQL) WithUsername ¶
WithUsername 设置数据库用户名
type PostgreSQL ¶
type PostgreSQL struct {
ModuleName string `mapstructure:"module-name" yaml:"module-name" json:"moduleName"` // 模块名称
Host string `mapstructure:"host" yaml:"host" json:"host" validate:"required"` // 数据库 IP 地址
Port string `mapstructure:"port" yaml:"port" json:"port" validate:"required"` // 端口
Config string `mapstructure:"config" yaml:"config" json:"config" validate:"required"` // 后缀配置
LogLevel string `mapstructure:"log-level" yaml:"log-level" json:"logLevel" validate:"required"` // SQL 日志等级
SlowThreshold int `mapstructure:"slow-threshold" yaml:"slow-threshold" json:"slowThreshold"` // 慢查询阈值(毫秒)
IgnoreRecordNotFoundError bool `mapstructure:"ignore-record-not-found-error" yaml:"ignore-record-not-found-error" json:"ignoreRecordNotFoundError"` // 是否忽略ErrRecordNotFound错误
Dbname string `mapstructure:"db-name" yaml:"db-name" json:"dbName" validate:"required"` // 数据库名称
Username string `mapstructure:"username" yaml:"username" json:"username" validate:"required"` // 数据库用户名
Password string `mapstructure:"password" yaml:"password" json:"password" validate:"required"` // 数据库密码
MaxIdleConns int `mapstructure:"max-idle-conns" yaml:"max-idle-conns" json:"maxIdleConns" validate:"min=0"` // 最大空闲连接数
MaxOpenConns int `mapstructure:"max-open-conns" yaml:"max-open-conns" json:"maxOpenConns" validate:"min=0"` // 最大连接数
ConnMaxIdleTime int `mapstructure:"conn-max-idle-time" yaml:"conn-max-idle-time" json:"connMaxIdleTime" validate:"min=0"` // 连接最大空闲时间 单位:秒
ConnMaxLifeTime int `mapstructure:"conn-max-life-time" yaml:"conn-max-life-time" json:"connMaxLifeTime" validate:"min=0"` // 连接最大生命周期 单位:秒
SkipDefaultTransaction bool `mapstructure:"skip-default-transaction" yaml:"skip-default-transaction" json:"skipDefaultTransaction"` // 跳过默认事务
PrepareStmt bool `mapstructure:"prepare-stmt" yaml:"prepare-stmt" json:"prepareStmt"` // 预编译语句
DisableForeignKeyConstraintWhenMigrating bool `` // 禁用自动创建外键约束
/* 161-byte string literal not displayed */
DisableNestedTransaction bool `mapstructure:"disable-nested-transaction" yaml:"disable-nested-transaction" json:"disableNestedTransaction"` // 禁用嵌套事务
AllowGlobalUpdate bool `mapstructure:"allow-global-update" yaml:"allow-global-update" json:"allowGlobalUpdate"` // 允许全局更新
QueryFields bool `mapstructure:"query-fields" yaml:"query-fields" json:"queryFields"` // 执行查询时选择所有字段
CreateBatchSize int `mapstructure:"create-batch-size" yaml:"create-batch-size" json:"createBatchSize"` // 批量创建大小
SingularTable bool `mapstructure:"singular-table" yaml:"singular-table" json:"singularTable"` // 使用单数表名
}
PostgreSQL PostgreSQL数据库配置
func NewPostgreSQLConfig ¶
func NewPostgreSQLConfig(opt *PostgreSQL) *PostgreSQL
NewPostgreSQLConfig 创建一个新的PostgreSQL配置实例
func (*PostgreSQL) Clone ¶
func (p *PostgreSQL) Clone() internal.Configurable
func (*PostgreSQL) Get ¶
func (p *PostgreSQL) Get() interface{}
func (*PostgreSQL) GetAllowGlobalUpdate ¶
func (p *PostgreSQL) GetAllowGlobalUpdate() bool
func (*PostgreSQL) GetConfig ¶
func (p *PostgreSQL) GetConfig() string
func (*PostgreSQL) GetCreateBatchSize ¶
func (p *PostgreSQL) GetCreateBatchSize() int
func (*PostgreSQL) GetDBName ¶
func (p *PostgreSQL) GetDBName() string
func (*PostgreSQL) GetDBType ¶
func (p *PostgreSQL) GetDBType() DBType
为PostgreSQL配置实现DatabaseProvider接口
func (*PostgreSQL) GetDisableForeignKeyConstraintWhenMigrating ¶
func (p *PostgreSQL) GetDisableForeignKeyConstraintWhenMigrating() bool
func (*PostgreSQL) GetDisableNestedTransaction ¶
func (p *PostgreSQL) GetDisableNestedTransaction() bool
func (*PostgreSQL) GetHost ¶
func (p *PostgreSQL) GetHost() string
func (*PostgreSQL) GetIgnoreRecordNotFoundError ¶
func (p *PostgreSQL) GetIgnoreRecordNotFoundError() bool
func (*PostgreSQL) GetLogLevel ¶
func (p *PostgreSQL) GetLogLevel() string
func (*PostgreSQL) GetModuleName ¶
func (p *PostgreSQL) GetModuleName() string
func (*PostgreSQL) GetPassword ¶
func (p *PostgreSQL) GetPassword() string
func (*PostgreSQL) GetPort ¶
func (p *PostgreSQL) GetPort() string
func (*PostgreSQL) GetPrepareStmt ¶
func (p *PostgreSQL) GetPrepareStmt() bool
func (*PostgreSQL) GetQueryFields ¶
func (p *PostgreSQL) GetQueryFields() bool
func (*PostgreSQL) GetSingularTable ¶
func (p *PostgreSQL) GetSingularTable() bool
func (*PostgreSQL) GetSkipDefaultTransaction ¶
func (p *PostgreSQL) GetSkipDefaultTransaction() bool
func (*PostgreSQL) GetSlowThreshold ¶
func (p *PostgreSQL) GetSlowThreshold() int
func (*PostgreSQL) GetUsername ¶
func (p *PostgreSQL) GetUsername() string
func (*PostgreSQL) Set ¶
func (p *PostgreSQL) Set(data interface{})
func (*PostgreSQL) SetCredentials ¶
func (p *PostgreSQL) SetCredentials(username, password string)
func (*PostgreSQL) SetDBName ¶
func (p *PostgreSQL) SetDBName(dbName string)
func (*PostgreSQL) SetHost ¶
func (p *PostgreSQL) SetHost(host string)
func (*PostgreSQL) SetPort ¶
func (p *PostgreSQL) SetPort(port string)
func (*PostgreSQL) Validate ¶
func (p *PostgreSQL) Validate() error
func (*PostgreSQL) WithConfig ¶
func (p *PostgreSQL) WithConfig(config string) *PostgreSQL
WithConfig 设置数据库配置参数
func (*PostgreSQL) WithConnMaxIdleTime ¶
func (p *PostgreSQL) WithConnMaxIdleTime(connMaxIdleTime int) *PostgreSQL
WithConnMaxIdleTime 设置连接最大空闲时间
func (*PostgreSQL) WithConnMaxLifeTime ¶
func (p *PostgreSQL) WithConnMaxLifeTime(connMaxLifeTime int) *PostgreSQL
WithConnMaxLifeTime 设置连接最大生命周期
func (*PostgreSQL) WithDbname ¶
func (p *PostgreSQL) WithDbname(dbname string) *PostgreSQL
WithDbname 设置数据库名称
func (*PostgreSQL) WithHost ¶
func (p *PostgreSQL) WithHost(host string) *PostgreSQL
WithHost 设置数据库主机地址
func (*PostgreSQL) WithLogLevel ¶
func (p *PostgreSQL) WithLogLevel(logLevel string) *PostgreSQL
WithLogLevel 设置日志级别
func (*PostgreSQL) WithMaxIdleConns ¶
func (p *PostgreSQL) WithMaxIdleConns(maxIdleConns int) *PostgreSQL
WithMaxIdleConns 设置最大空闲连接数
func (*PostgreSQL) WithMaxOpenConns ¶
func (p *PostgreSQL) WithMaxOpenConns(maxOpenConns int) *PostgreSQL
WithMaxOpenConns 设置最大连接数
func (*PostgreSQL) WithModuleName ¶
func (p *PostgreSQL) WithModuleName(moduleName string) *PostgreSQL
WithModuleName 设置模块名称
func (*PostgreSQL) WithPassword ¶
func (p *PostgreSQL) WithPassword(password string) *PostgreSQL
WithPassword 设置数据库密码
func (*PostgreSQL) WithPort ¶
func (p *PostgreSQL) WithPort(port string) *PostgreSQL
WithPort 设置数据库端口
func (*PostgreSQL) WithUsername ¶
func (p *PostgreSQL) WithUsername(username string) *PostgreSQL
WithUsername 设置数据库用户名
type SQLite ¶
type SQLite struct {
ModuleName string `mapstructure:"module-name" yaml:"module-name" json:"moduleName"` // 模块名称
Config string `mapstructure:"config" yaml:"config" json:"config" validate:"required"` // 后缀配置
LogLevel string `mapstructure:"log-level" yaml:"log-level" json:"logLevel" validate:"required"` // SQL 日志等级
SlowThreshold int `mapstructure:"slow-threshold" yaml:"slow-threshold" json:"slowThreshold"` // 慢查询阈值(毫秒)
IgnoreRecordNotFoundError bool `mapstructure:"ignore-record-not-found-error" yaml:"ignore-record-not-found-error" json:"ignoreRecordNotFoundError"` // 是否忽略ErrRecordNotFound错误
DbPath string `mapstructure:"db-path" yaml:"db-path" json:"dbPath"` // SQLite 文件存放位置
Vacuum bool `mapstructure:"vacuum" yaml:"vacuum" json:"vacuum"` // 是否执行清除命令
MaxIdleConns int `mapstructure:"max-idle-conns" yaml:"max-idle-conns" json:"maxIdleConns" validate:"min=0"` // 最大空闲连接数
MaxOpenConns int `mapstructure:"max-open-conns" yaml:"max-open-conns" json:"maxOpenConns" validate:"min=0"` // 最大连接数
ConnMaxIdleTime int `mapstructure:"conn-max-idle-time" yaml:"conn-max-idle-time" json:"connMaxIdleTime" validate:"min=0"` // 连接最大空闲时间 单位:秒
ConnMaxLifeTime int `mapstructure:"conn-max-life-time" yaml:"conn-max-life-time" json:"connMaxLifeTime" validate:"min=0"` // 连接最大生命周期 单位:秒
SkipDefaultTransaction bool `mapstructure:"skip-default-transaction" yaml:"skip-default-transaction" json:"skipDefaultTransaction"` // 跳过默认事务
PrepareStmt bool `mapstructure:"prepare-stmt" yaml:"prepare-stmt" json:"prepareStmt"` // 预编译语句
DisableForeignKeyConstraintWhenMigrating bool `` // 禁用自动创建外键约束
/* 161-byte string literal not displayed */
DisableNestedTransaction bool `mapstructure:"disable-nested-transaction" yaml:"disable-nested-transaction" json:"disableNestedTransaction"` // 禁用嵌套事务
AllowGlobalUpdate bool `mapstructure:"allow-global-update" yaml:"allow-global-update" json:"allowGlobalUpdate"` // 允许全局更新
QueryFields bool `mapstructure:"query-fields" yaml:"query-fields" json:"queryFields"` // 执行查询时选择所有字段
CreateBatchSize int `mapstructure:"create-batch-size" yaml:"create-batch-size" json:"createBatchSize"` // 批量创建大小
SingularTable bool `mapstructure:"singular-table" yaml:"singular-table" json:"singularTable"` // 使用单数表名
}
SQLite SQLite数据库配置
func (*SQLite) Clone ¶
func (s *SQLite) Clone() internal.Configurable
func (*SQLite) GetAllowGlobalUpdate ¶
func (*SQLite) GetCreateBatchSize ¶
func (*SQLite) GetDisableForeignKeyConstraintWhenMigrating ¶
func (*SQLite) GetDisableNestedTransaction ¶
func (*SQLite) GetIgnoreRecordNotFoundError ¶
func (*SQLite) GetLogLevel ¶
func (*SQLite) GetModuleName ¶
func (*SQLite) GetPassword ¶
func (*SQLite) GetPrepareStmt ¶
func (*SQLite) GetQueryFields ¶
func (*SQLite) GetSingularTable ¶
func (*SQLite) GetSkipDefaultTransaction ¶
func (*SQLite) GetSlowThreshold ¶
func (*SQLite) GetUsername ¶
func (*SQLite) SetCredentials ¶
func (*SQLite) WithConnMaxIdleTime ¶
WithConnMaxIdleTime 设置连接最大空闲时间
func (*SQLite) WithConnMaxLifeTime ¶
WithConnMaxLifeTime 设置连接最大生命周期
func (*SQLite) WithDbPath ¶
WithDbPath 设置SQLite数据库文件路径
func (*SQLite) WithLogLevel ¶
WithLogLevel 设置日志级别
func (*SQLite) WithMaxIdleConns ¶
WithMaxIdleConns 设置最大空闲连接数
func (*SQLite) WithMaxOpenConns ¶
WithMaxOpenConns 设置最大连接数
func (*SQLite) WithModuleName ¶
WithModuleName 设置模块名称