Documentation ¶
Index ¶
- Constants
- Variables
- func SetTimeZone() error
- type CallBackFunc
- type CompoundIndex
- type DBInterface
- type DbActionFunc
- type IRedisMaster
- type InterfaceCompoundIndexes
- type InterfaceSession
- type InterfaceTableInit
- type JSONTime
- func (p JSONTime) Addr() *JSONTime
- func (p *JSONTime) Convert2Time() time.Time
- func (p *JSONTime) Date() *JSONTime
- func (p *JSONTime) FromDB(data []byte) error
- func (p *JSONTime) GobDecode(data []byte) error
- func (p *JSONTime) GobEncode() ([]byte, error)
- func (p *JSONTime) MarshalJSON() ([]byte, error)
- func (p *JSONTime) Scan(v interface{}) error
- func (p *JSONTime) SetByTime(timeVal time.Time)
- func (p *JSONTime) String() string
- func (p *JSONTime) StringFormat(layout string) string
- func (p *JSONTime) Time() time.Time
- func (p *JSONTime) ToDB() (b []byte, err error)
- func (p *JSONTime) UnmarshalJSON(data []byte) error
- func (p *JSONTime) Value() (driver.Value, error)
- type Map
- type MyBase
- type Option
- type RedisOption
- type SNUpdate
- type Session
- func (s *Session) BeginTx() (newSn InterfaceSession, err error)
- func (s *Session) Close()
- func (s *Session) Commit() error
- func (s *Session) Delete(conditionBean interface{}) (int64, error)
- func (s *Session) Get(bean interface{}) (has bool, err error)
- func (s *Session) Insert(beans ...interface{}) (int64, error)
- func (s *Session) InsertOne(bean interface{}) (int64, error)
- func (s *Session) IsTx() bool
- func (s *Session) NewUpdater(condition interface{}) (up *SNUpdate)
- func (s *Session) PubForCache(bean interface{}) (err error)
- func (s *Session) RollBack() error
- func (s *Session) Session() *xorm.Session
- func (s *Session) Sync(beans ...interface{}) error
- func (s *Session) Update(up *Updater) (int64, error)
- func (s *Session) WrapTx(callBackFunc CallBackFunc) (err error)
- func (s *Session) WrapTxForCache(bean interface{}, fn CallBackFunc) error
- type Updater
Constants ¶
const ( //TimeZone ... TimeZone = "Asia/Shanghai" //Custom ... Custom = "2006-01-02 15:04:05" )
const (
RedisDBCache = 1
)
cache redis constant
Variables ¶
var DefOption = &Option{ Username: "root", Password: "password", DBName: "g_database", Link: "tcp(127.0.0.1:3306)/{db}?charset=utf8mb4&collation=utf8mb4_bin&timeout=90s&loc=Local", UseCache: false, ShowSQL: true, MaxIdleConnections: 10, MaxOpenConnections: 100, MaxConnLifetimeSeconds: 31, }
DefOption ...默认数据库连接参数
var DefRedisOption = &RedisOption{
Addr: "127.0.0.1:6379",
Password: "",
DB: 0,
MaxRetries: 5,
MinIdleConnections: 10,
MaxConnAgeSeconds: 10 * 60,
}
DefRedisOption redis 连接默认参数
Functions ¶
Types ¶
type CompoundIndex ¶
type CompoundIndex struct { //索引字段映射关系,k:数据库中的字段名,v:struct的field Columns Map Unique bool // contains filtered or unexported fields }
CompoundIndex 复合索引
type DBInterface ¶
type DBInterface interface { SetOpt(opt *Option) DBInterface SetOutputFilePath(fName string) DBInterface SetRedisClient(redisClient IRedisMaster) DBInterface Dial() (err error) RegisterTable(tables ...interface{}) Sync() error Engine() xorm.EngineInterface Session() *Session CreateDB() (err error) RedisClient() IRedisMaster MemCache() *cache.Cache }
DBInterface 数据库操作接口
var XDB DBInterface = newXdb()
XDB 全局db对象
type IRedisMaster ¶
type IRedisMaster interface { SetCfgOpt(*RedisOption) IRedisMaster Dial() error SelectDBPipe(int, func(redis.Pipeliner) error) error SelectDBPipeTX(int, func(redis.Pipeliner) error) error C() *redis.Client Client() *redis.Client }
IRedisMaster ...Redis操作接口
var GRedis IRedisMaster = new(redisA)
GRedis 全局变量
type InterfaceCompoundIndexes ¶
type InterfaceCompoundIndexes interface { CompoundIndexes() []*CompoundIndex UseCache() bool }
InterfaceCompoundIndexes ...联合索引接口 实现了此接口的数据,将会经过Redis缓存
type InterfaceSession ¶
type InterfaceSession interface { Session() *xorm.Session Sync(beans ...interface{}) error Insert(beans ...interface{}) (int64, error) InsertOne(bean interface{}) (int64, error) Update(up *Updater) (int64, error) Delete(conditionBean interface{}) (int64, error) BeginTx() (InterfaceSession, error) IsTx() bool RollBack() error Commit() error Close() Get(bean interface{}) (has bool, err error) WrapTx(callBackFunc CallBackFunc) (err error) PubForCache(bean interface{}) (err error) WrapTxForCache(bean interface{}, fn CallBackFunc) error NewUpdater(in interface{}) *SNUpdate }
InterfaceSession ...数据库会话接口
type InterfaceTableInit ¶
type InterfaceTableInit interface {
InitData() (err error)
}
InterfaceTableInit ...数据表初始化接口
type JSONTime ¶
JSONTime ...
func NewJSONTimeOfTime ¶
NewJSONTimeOfTime 时间转换为JSONTime
func (*JSONTime) StringFormat ¶
StringFormat 转换为固定格式字符串
func (*JSONTime) UnmarshalJSON ¶
UnmarshalJSON ...
type MyBase ¶
type MyBase struct { ID int64 `json:"id,omitempty" xorm:"pk autoincr"` Version int64 `json:"version,omitempty" xorm:"notnull version"` Created *JSONTime `json:"created,omitempty" xorm:"notnull created index"` Updated *JSONTime `json:"updated,omitempty" xorm:"notnull updated"` // contains filtered or unexported fields }
MyBase xorm MySQL model base
func (*MyBase) Sn ¶
func (b *MyBase) Sn() InterfaceSession
Sn ... session 对象,如果上下文session对象为空,则初始化Engine session
type Option ¶
type Option struct { Username string `yaml:"username" mapstructure:"username"` Password string `yaml:"password" mapstructure:"password"` DBName string `yaml:"db_name" mapstructure:"db_name"` Link string `yaml:"link" mapstructure:"link"` UseCache bool `yaml:"use_cache" mapstructure:"use_cache"` ShowSQL bool `yaml:"show_sql" mapstructure:"show_sql"` MaxIdleConnections int `yaml:"max_idle_connections" mapstructure:"max_idle_connections"` MaxOpenConnections int `yaml:"max_open_connections" mapstructure:"max_open_connections"` MaxConnLifetimeSeconds int `yaml:"max_conn_lifetime_seconds" mapstructure:"max_conn_lifetime_seconds"` }
Option ...配置信息
type RedisOption ¶
type RedisOption struct { // The network type, either tcp or unix. // Default is tcp. //Network string // host:port address. Addr string `yaml:"addr" mapstructure:"addr"` // Optional password. Must match the password specified in the // requirepass server configuration option. Password string `yaml:"password" mapstructure:"password"` // Database to be selected after connecting to the server. DB int `yaml:"db" mapstructure:"db"` // Maximum number of retries before giving up. // Default is to not retry failed commands. MaxRetries int `yaml:"max_retries" mapstructure:"max_retries"` // Maximum number of socket connections. // Default is 10 connections per every CPU as reported by runtime.NumCPU. //PoolSize int // Minimum number of idle connections which is useful when establishing // new connection is slow. //空闲连接数 MinIdleConnections int `yaml:"min_idle_connections" mapstructure:"min_idle_connections"` // Connection age at which client retires (closes) the connection. // Default is to not close aged connections. //连接状态最长时间,超出时间,会被强制关闭,建议10分钟 MaxConnAgeSeconds int `yaml:"max_conn_age_seconds" mapstructure:"max_conn_age_seconds"` }
RedisOption 配置参数
type SNUpdate ¶
type SNUpdate struct {
// contains filtered or unexported fields
}
SNUpdate ...
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session 数据会话
func (*Session) BeginTx ¶
func (s *Session) BeginTx() (newSn InterfaceSession, err error)
BeginTx 开启一个事务
func (*Session) Insert ¶
Insert ...需要触发缓存操作,必须逐条插入; 传入的参数,必须都是切片 如果确定对象不使用缓存,则可以使用orm Session Insert 进行批量插入
func (*Session) NewUpdater ¶
NewUpdater ...链式操作的update
func (*Session) PubForCache ¶
PubForCache ... 发布删除缓存主题,并删除Redis缓存
func (*Session) WrapTx ¶
func (s *Session) WrapTx(callBackFunc CallBackFunc) (err error)
WrapTx 开启一个事务处理函数
func (*Session) WrapTxForCache ¶
func (s *Session) WrapTxForCache(bean interface{}, fn CallBackFunc) error
WrapTxForCache ...发布删除缓存的消息 bean 带有查询条件的对象 fn 数据库操作 第一个参数,删除缓存需要的对象 第二个参数,是一个数据库执行方法