Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// distributed transaction support
DistributedTransaction bool `yaml:"distributed_transaction"`
// map table name and configuration
Tables map[string]*TableConfig `yaml:"tables"`
// if true skip auto create database
SkipAutoSetup bool `yaml:"skip_auto_setup"`
}
A Config is a database configuration includes database sharding definition.
func Get ¶
Get get database configuration.
If use this method, must call after Load(). If call this method before Load(), it returns error
func (*Config) IsShardTable ¶
IsShardTable returns whether 'is_shard' parameter is defined or not in table configuration.
func (*Config) ShardColumnName ¶
ShardColumnName column name of unique id for all shards
func (*Config) ShardKeyColumnName ¶
ShardKeyColumnName column name for deciding sharding target
type DatabaseConfig ¶
type DatabaseConfig struct {
// database name of MySQL or database file path of SQLite
NameOrPath string `yaml:"database"`
// adapter name ( 'mysql' or 'sqlite3' )
Adapter string `yaml:"adapter"`
// database encoding like utf8mb4
Encoding string `yaml:"encoding"`
// login user name to database server
Username string `yaml:"username"`
// login password to database server
Password string `yaml:"password"`
// master server's dsn list ( currently support single master only )
Masters []string `yaml:"master"`
// slave server's dsn list ( currently not support )
Slaves []string `yaml:"slave"`
// backup server's dsn list ( currently not support )
Backups []string `yaml:"backup"`
}
DatabaseConfig type for database definition
type TableConfig ¶
type TableConfig struct {
DatabaseConfig `yaml:",inline"`
// enable sharding in this table
IsShard bool `yaml:"shard"`
// unique id's column for all shards. id is published by sequencer
ShardColumnName string `yaml:"shard_column"`
// column name for deciding sharding target
// this column's value is passed to sharding algorithm
// if not specified, shard_column value is used as shard_key
ShardKeyColumnName string `yaml:"shard_key"`
// sharding algorithm ( default: modulo )
Algorithm string `yaml:"algorithm"`
// support unique id in between all shards
Sequencer *DatabaseConfig `yaml:"sequencer"`
// shard configurations
Shards []map[string]*DatabaseConfig `yaml:"shards"`
}
TableConfig type for table definition
func (*TableConfig) Error ¶
func (c *TableConfig) Error() error
Error returns error of this table configuration.
func (*TableConfig) IsUsedSequencer ¶
func (c *TableConfig) IsUsedSequencer() bool
IsUsedSequencer returns whether 'sequencer' parameter is defined or not in table configuration.
func (*TableConfig) ShardConfigByName ¶
func (c *TableConfig) ShardConfigByName(shardName string) *DatabaseConfig
ShardConfigByName returns DatabaseConfig instance by name of shards