github.com/wfusion/gofusion@v1.1.14/db/types.go (about) 1 package db 2 3 import ( 4 "reflect" 5 6 "gorm.io/gorm/clause" 7 8 "github.com/wfusion/gofusion/common/infra/drivers/orm" 9 "github.com/wfusion/gofusion/common/utils" 10 "github.com/wfusion/gofusion/log" 11 ) 12 13 const ( 14 ErrDuplicatedName utils.Error = "duplicated database name" 15 ErrDatabaseNotFound utils.Error = "not found database to use" 16 ) 17 18 var ( 19 customLoggerType = reflect.TypeOf((*customLogger)(nil)).Elem() 20 gormClauseExpressionType = reflect.TypeOf((*clause.Expression)(nil)).Elem() 21 ) 22 23 // Conf 24 //nolint: revive // struct tag too long issue 25 type Conf struct { 26 orm.Option `yaml:",inline" json:",inline" toml:",inline"` 27 AutoIncrementIncrement int64 `yaml:"auto_increment_increment" json:"auto_increment_increment" toml:"auto_increment_increment"` 28 Sharding []shardingConf `yaml:"sharding" json:"sharding" toml:"sharding"` 29 EnableLogger bool `yaml:"enable_logger" json:"enable_logger" toml:"enable_logger" default:"false"` 30 LoggerConfig struct { 31 Logger string `yaml:"logger" json:"logger" toml:"logger" default:"github.com/wfusion/gofusion/log/customlogger.gormLogger"` 32 LogInstance string `yaml:"log_instance" json:"log_instance" toml:"log_instance" default:"default"` 33 LogLevel string `yaml:"log_level" json:"log_level" toml:"log_level"` 34 SlowThreshold string `yaml:"slow_threshold" json:"slow_threshold" toml:"slow_threshold"` 35 } `yaml:"logger_config" json:"logger_config" toml:"logger_config"` 36 } 37 38 // shardingConf 39 //nolint: revive // struct tag too long issue 40 type shardingConf struct { 41 Table string `yaml:"table"` 42 Suffix string `yaml:"suffix"` 43 Columns []string `yaml:"columns"` 44 ShardingKeyExpr string `yaml:"sharding_key_expr"` 45 ShardingKeyByRawValue bool `yaml:"sharding_key_by_raw_value"` 46 ShardingKeysForMigrating []string `yaml:"sharding_keys_for_migrating"` 47 NumberOfShards uint `yaml:"number_of_shards"` 48 IDGen string `yaml:"idgen" default:"github.com/wfusion/gofusion/common/infra/drivers/orm/idgen.NewSnowflake"` 49 } 50 51 type customLogger interface { 52 Init(log log.Loggable, appName, name string) 53 }