Documentation ¶
Index ¶
- Constants
- func CreateDB(logger log.Logger, config Config) error
- func DropDB(logger log.Logger, config Config) error
- func GetMigrationsDriver(name string) (source.Driver, error)
- func RegisterDriver(name string, driver Driver)
- func RegisterMigrationsDriver(name string, driver source.Driver)
- func SourceDesensitization(source string) string
- type Config
- type DB
- type Driver
- type Mysql
- func (m *Mysql) CreateDB(logger log.Logger, config Config) error
- func (m *Mysql) DropDB(logger log.Logger, config Config) error
- func (m *Mysql) GetDatabaseName(source string) string
- func (*Mysql) GetMigrationsDriver() (source.Driver, error)
- func (*Mysql) MigrateOptions() map[string]string
- func (*Mysql) Open(source string) gorm.Dialector
- func (m *Mysql) ParseSource(source string) error
- func (m *Mysql) ToMigrateDriver(source string) (string, database.Driver, error)
- type Sqlite
- func (*Sqlite) CreateDB(logger log.Logger, config Config) error
- func (*Sqlite) DropDB(logger log.Logger, config Config) error
- func (s *Sqlite) GetDatabaseName(source string) string
- func (*Sqlite) GetMigrationsDriver() (source.Driver, error)
- func (*Sqlite) MigrateOptions() map[string]string
- func (*Sqlite) Open(source string) gorm.Dialector
- func (s *Sqlite) ParseSource(source string) error
- func (*Sqlite) ToMigrateDriver(source string) (string, database.Driver, error)
Constants ¶
View Source
const ( LogLevelSilent = "silent" LogLevelError = "error" LogLevelWarn = "warn" LogLevelInfo = "info" )
View Source
const MysqlDriver = "mysql"
View Source
const PostgresDriver = "postgres"
View Source
const SqliteDriver = "sqlite"
Variables ¶
This section is empty.
Functions ¶
func RegisterDriver ¶
func SourceDesensitization ¶
Types ¶
type Config ¶
type Config struct { Driver string `yaml:"driver" mapstructure:"driver"` Source string `yaml:"source" mapstructure:"source"` ConnMaxIdleTime time.Duration `yaml:"conn_max_idle_time" mapstructure:"conn_max_idle_time"` ConnMaxLifeTime time.Duration `yaml:"conn_max_life_time" mapstructure:"conn_max_life_time"` MaxIdleConn int `yaml:"max_idle_conn" mapstructure:"max_idle_conn"` MaxOpenConn int `yaml:"max_open_conn" mapstructure:"max_open_conn"` LogLevel string `yaml:"log_level" mapstructure:"log_level"` EnableMetric bool `yaml:"enable_metric" mapstructure:"enable_metric"` RefreshMetricInterval time.Duration `yaml:"refresh_metric_interval" mapstructure:"refresh_metric_interval"` }
func NewDefConfig ¶
func NewDefConfig() Config
func (Config) GetDatabaseName ¶
func (Config) GetLogLevel ¶
func (Config) MarshalJSON ¶
func (Config) MarshalYAML ¶
type DB ¶
type DB interface { Model(value any) DB Where(query any, args ...any) DB Limit(limit int) DB Scopes(funcs ...func(DB) DB) DB Offset(offset int) DB Order(value any) DB Count(count *int64) DB Group(query string) DB RowsAffected(number int64) DB Select(query any, args ...any) DB Distinct(args ...any) DB Find(dest any, conds ...any) (err error) First(dest any, conds ...any) (found bool, err error) MustFirst(dest any, conds ...any) (err error) Exec(sql string, values ...any) error Create(value any) error Update(column string, value any) error Updates(values any) error Transaction(fn func(tx DB) error) error Begin() DB Commit() error Rollback() error AutoMigrate(dst ...any) error GetSource() string GetDriver() Driver Close() error WithContext(ctx context.Context) DB WithLogger(l log.Logger) DB }
func NewMemoryDB ¶
type Driver ¶
type Driver interface { Open(source string) gorm.Dialector ParseSource(source string) error GetDatabaseName(source string) string CreateDB(logger log.Logger, config Config) error DropDB(logger log.Logger, config Config) error MigrateOptions() map[string]string GetMigrationsDriver() (source.Driver, error) ToMigrateDriver(source string) (string, database.Driver, error) }
type Mysql ¶
type Mysql struct {
// contains filtered or unexported fields
}
func (*Mysql) GetDatabaseName ¶
func (*Mysql) MigrateOptions ¶
func (*Mysql) ParseSource ¶
type Sqlite ¶
type Sqlite struct {
// contains filtered or unexported fields
}
func (*Sqlite) GetDatabaseName ¶
func (*Sqlite) MigrateOptions ¶
func (*Sqlite) ParseSource ¶
Click to show internal directories.
Click to hide internal directories.