Documentation ¶
Index ¶
- type Cluster
- func (c *Cluster) Exec(sql string, args ...interface{}) error
- func (c *Cluster) Master() *sql.DB
- func (c *Cluster) Run(fn func(master *sql.DB, slave *sql.DB) error) error
- func (c *Cluster) RunShard(key string, fn func(master *sql.DB, slave *sql.DB) error) error
- func (c *Cluster) Slave() *sql.DB
- func (c *Cluster) SlaveByKey(key string) *sql.DB
- func (c *Cluster) SlaveBySelector(selector Selector) *sql.DB
- func (c *Cluster) Transaction(fn func(tx *sql.Tx) error) error
- type ConnectionOption
- type ConnectionOptions
- type Enum
- type IPV4
- type Selector
- type SelectorFunc
- type StringArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
func OpenCluster ¶
func OpenCluster(name string, selector Selector, masterOption ConnectionOptions, slaveOptions []ConnectionOptions) (*Cluster, error)
OpenCluster init new gorm client cluster with mysql database. name is instance name of current mysql instance. selector to select which slave node to use. masterOption is master node options slaveOptions are slave nodes options
func (*Cluster) Exec ¶
Exec will do update/insert/delete operation with master node. 在主节点上执行 更新/插入/删除 操作。
func (*Cluster) Run ¶
Run will do operation on master or slave node with user choose. 用户可选的在何种节点上执行操作。
func (*Cluster) RunShard ¶
Run will do operation on master or slave node with user choose, with key to select which slave node. 用户可选的在何种节点上执行操作,key 用来选择从节点。
func (*Cluster) SlaveByKey ¶
SlaveByKey get slave db use shard `Selector` with shard key. 使用key来选择从节点。
func (*Cluster) SlaveBySelector ¶
SlaveBySelector get slave db use user `Selector`. 使用用户指定的选择器选择从节点。
type ConnectionOption ¶
type ConnectionOption func(options *ConnectionOptions)
ConnectionOption is helper function to modify database pool options
func WithConnMaxIdleTime ¶
func WithConnMaxIdleTime(d time.Duration) ConnectionOption
func WithDriverName ¶
func WithDriverName(name string) ConnectionOption
func WithDsn ¶
func WithDsn(dsn string) ConnectionOption
func WithMaxIdleConn ¶
func WithMaxIdleConn(n int) ConnectionOption
func WithMaxOpenConn ¶
func WithMaxOpenConn(n int) ConnectionOption
type ConnectionOptions ¶
type ConnectionOptions struct { DriverName string Dsn string MaxIdleConn int MaxOpenConn int ConnMaxLifeTime time.Duration }
func NewDefaultConnectionOptions ¶
func NewDefaultConnectionOptions() ConnectionOptions
type Enum ¶
type Enum struct {
// contains filtered or unexported fields
}
Enum present a selectable of value which store in database in int mode, but in application is string mode, this will translate automatically.
type IPV4 ¶
type IPV4 struct {
// contains filtered or unexported fields
}
IPV4 present a selectable of ipv4 address which store in database in int mode, but in application is ipv4 mode, this will translate automatically.
type SelectorFunc ¶
func RandomSelector ¶
func RandomSelector() SelectorFunc
func RoundRobinSelector ¶
func RoundRobinSelector() SelectorFunc
func ShardSelector ¶
func ShardSelector(key string) SelectorFunc
func (SelectorFunc) SelectDB ¶
func (fn SelectorFunc) SelectDB(n int) int
type StringArray ¶
type StringArray []string
StringArray present a slice of array which store in database in string mode, but in application is string slice mode, this will translate automatically.
func (*StringArray) Scan ¶
func (a *StringArray) Scan(src interface{}) error
func (StringArray) String ¶
func (a StringArray) String() string