Documentation
¶
Index ¶
- Constants
- Variables
- func DaoStructToMap(data interface{}) map[string]interface{}
- func GetModelFullNameAndValue(m interface{}) (string, reflect.Value)
- func ReflectValueToStr(kind reflect.Kind, v reflect.Value) string
- func RegisterModel(m Model)
- func SetGlobalCacheUtil(cacheUtil CacheInterface)
- func SetLogger(newLogger Logger)
- type CacheInterface
- type DBClient
- func (db *DBClient) DataSource(ctx context.Context, isReadOnly bool) *gorm.DB
- func (db *DBClient) GetDBClientConfig() *DBClientConfig
- func (db *DBClient) ReadOnly() *gorm.DB
- func (db *DBClient) ReadOnlyTable(ctx context.Context, name string) *gorm.DB
- func (db *DBClient) Table(ctx context.Context, name string) *gorm.DB
- func (db *DBClient) Transaction(ctx context.Context, tansFunc TransactionFunction) (err error)
- type DBClientConfig
- type DBClientInterface
- type DBIDInt
- type DBIDInt64
- type DBUpdateAt
- type DSNConfig
- type DaoBase
- func (daoBase *DaoBase) Create(ctx context.Context) error
- func (daoBase *DaoBase) DBClient() DBClientInterface
- func (daoBase *DaoBase) Delete(ctx context.Context) error
- func (daoBase *DaoBase) GetDefaultMapView() map[string]interface{}
- func (daoBase *DaoBase) GetOldData() map[string]interface{}
- func (daoBase *DaoBase) GetUniqKey() string
- func (daoBase *DaoBase) IsLoadFromDB() bool
- func (daoBase *DaoBase) IsNewRow() bool
- func (daoBase *DaoBase) Load(ctx context.Context) error
- func (daoBase *DaoBase) PKFieldsStr() string
- func (daoBase *DaoBase) Save(ctx context.Context) error
- func (daoBase *DaoBase) TableName() string
- func (daoBase *DaoBase) Update(ctx context.Context) error
- type DefaultLogger
- type EndpointConfig
- type Field
- type FieldTag
- type LogData
- type Logger
- type Model
- type ModelDef
- type NopCacheUtil
- type Option
- func OptionNewForceCache(newForceCache bool) Option
- func OptionSetCacheExpireTS(expireTS int) Option
- func OptionSetCacheUtil(cacheUtil CacheInterface) Option
- func OptionSetFieldNameCreatedAt(fieldName string) Option
- func OptionSetFieldNameUpdatedAt(fieldName string) Option
- func OptionSetUseCache(useCache bool) Option
- type OptionFunc
- type TransactionFunction
Constants ¶
View Source
const ( LevelDebug = "DEBUG" LevelInfo = "INFO" LevelWarn = "WARN" LevelError = "ERROR" )
View Source
const (
TypeNameTime = "Time"
)
Variables ¶
View Source
var ( DaoCacheExpire int = 86400 * 7 // dao缓存超时时间 DaoCachePrefix string = "daocache" // dao缓存key前缀 FieldNameCreatedAt = "CreatedAt" FieldNameUpdatedAt = "UpdatedAt" )
全局属性变量 可以配置成自己需要的值
Functions ¶
Types ¶
type CacheInterface ¶
type DBClient ¶
func (*DBClient) DataSource ¶
DataSource 设定数据源
func (*DBClient) GetDBClientConfig ¶
func (db *DBClient) GetDBClientConfig() *DBClientConfig
func (*DBClient) ReadOnlyTable ¶
ReadOnlyTable 设定只读表名
func (*DBClient) Transaction ¶
func (db *DBClient) Transaction(ctx context.Context, tansFunc TransactionFunction) (err error)
type DBClientConfig ¶
type DBClientConfig struct { // 主dsn配置 DSN *DSNConfig `yaml:"dsn"` // 只读dsn配置 ReadDSN []*DSNConfig `yaml:"readDSN"` // 最大可用数量 Active int `yaml:"active"` // 最大闲置数量 Idle int `yaml:"idle"` // 闲置超时时间 IdleTimeout ctime.Duration `yaml:"idleTimeout"` // 查询超时时间 QueryTimeout ctime.Duration `yaml:"queryTimeout"` // 执行超时时间 ExecTimeout ctime.Duration `yaml:"execTimeout"` // 事务超时时间 TranTimeout ctime.Duration `yaml:"tranTimeout"` }
type DBClientInterface ¶
type DBUpdateAt ¶
type DSNConfig ¶
type DSNConfig struct { UserName string `yaml:"userName"` Password string `yaml:"password"` Endpoint *EndpointConfig `yaml:"endpoint"` DBName string `yaml:"dbName"` Options []string `yaml:"options"` }
DSN配置
type DaoBase ¶
type DaoBase struct {
// contains filtered or unexported fields
}
func NewDaoBase ¶
func NewDaoBaseNoLoad ¶
不加载数据的 获取model的daobase 目的为了获取对应的daobase 方法拿到底层的模型函数
func NewDaoBaseWithTX ¶
func NewDaoBaseWithTX(ctx context.Context, model Model, tx DBClientInterface, options ...Option) (*DaoBase, error)
支持事务
func (*DaoBase) DBClient ¶
func (daoBase *DaoBase) DBClient() DBClientInterface
func (*DaoBase) GetDefaultMapView ¶
dao默认转map结构
func (*DaoBase) GetOldData ¶
func (*DaoBase) GetUniqKey ¶
func (*DaoBase) IsLoadFromDB ¶
type DefaultLogger ¶
type DefaultLogger struct{}
type EndpointConfig ¶
type Field ¶
type Field struct { Name string StructField *reflect.StructField Tag *FieldTag Kind reflect.Kind ColumnName string }
func (*Field) IsPrimaryKey ¶
type FieldTag ¶
type FieldTag struct { ColumnName string Val string IsPK bool Ignore bool ColumnDefault string HaveColumnDefault bool // 是否有设置默认值 }
func NewFieldTag ¶
type Model ¶
type Model interface { TableName() string DBName() string DBClient() DBClientInterface GetDaoBase() *DaoBase SetDaoBase(myDaoBase *DaoBase) }
模型
type ModelDef ¶
type ModelDef struct { ModelType reflect.Type FullName string PKFields map[string]*Field Fields map[string]*Field // contains filtered or unexported fields }
模型定义
func NewModelDef ¶
func NewModelDef(m interface{}) *ModelDef
type NopCacheUtil ¶
type NopCacheUtil struct{}
func (*NopCacheUtil) Del ¶
func (ncu *NopCacheUtil) Del(ctx context.Context, key string) (err error)
type Option ¶
type Option interface {
Apply(*DaoBase)
}
func OptionSetCacheExpireTS ¶
func OptionSetUseCache ¶
type OptionFunc ¶
type OptionFunc func(daoBase *DaoBase)
func (OptionFunc) Apply ¶
func (of OptionFunc) Apply(daoBase *DaoBase)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.