config

package
v1.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 4 Imported by: 0

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

func Get() (*Config, error)

Get get database configuration.

If use this method, must call after Load(). If call this method before Load(), it returns error

func Load

func Load(configPath string) (*Config, error)

Load load database configuration by file path.

func (*Config) IsShardTable

func (c *Config) IsShardTable(tableName string) bool

IsShardTable returns whether 'is_shard' parameter is defined or not in table configuration.

func (*Config) ShardColumnName

func (c *Config) ShardColumnName(tableName string) string

ShardColumnName column name of unique id for all shards

func (*Config) ShardKeyColumnName

func (c *Config) ShardKeyColumnName(tableName string) string

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL