Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type ConnPool
- func (pool *ConnPool) BeginTx(ctx context.Context, opt *sql.TxOptions) (gorm.ConnPool, error)
- func (pool *ConnPool) Commit() error
- func (pool ConnPool) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (pool *ConnPool) Ping() error
- func (pool ConnPool) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (pool ConnPool) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (pool ConnPool) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (pool *ConnPool) Rollback() error
- func (pool *ConnPool) String() string
- type Sharding
Constants ¶
View Source
const ( // Use Snowflake primary key generator PKSnowflake = iota // Use PostgreSQL sequence primary key generator PKPGSequence // Use custom primary key generator PKCustom )
Variables ¶
View Source
var ( ErrMissingShardingKey = errors.New("sharding key or id required, and use operator =") ErrInvalidID = errors.New("invalid id format") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // When DoubleWrite enabled, data will double write to both main table and sharding table. DoubleWrite bool // ShardingKey specifies the table column you want to used for sharding the table rows. // For example, for a product order table, you may want to split the rows by `user_id`. ShardingKey string // NumberOfShards specifies how many tables you want to sharding. NumberOfShards uint // ShardingAlgorithm specifies a function to generate the sharding // table's suffix by the column value. // For example, this function implements a mod sharding algorithm. // // func(value interface{}) (suffix string, err error) { // if uid, ok := value.(int64);ok { // return fmt.Sprintf("_%02d", user_id % 64), nil // } // return "", errors.New("invalid user_id") // } ShardingAlgorithm func(columnValue interface{}) (suffix string, err error) // ShardingAlgorithmByPrimaryKey specifies a function to generate the sharding // table's suffix by the primary key. Used when no sharding key specified. // For example, this function use the Snowflake library to generate the suffix. // // func(id int64) (suffix string) { // return fmt.Sprintf("_%02d", snowflake.ParseInt64(id).Node()) // } ShardingAlgorithmByPrimaryKey func(id int64) (suffix string) // PrimaryKeyGenerator specifies the primary key generate algorithm. // Used only when insert and the record does not contains an id field. // Options are PKSnowflake, PKPGSequence and PKCustom. // When use PKCustom, you should also specify PrimaryKeyGeneratorFn. PrimaryKeyGenerator int // PrimaryKeyGeneratorFn specifies a function to generate the primary key. // When use auto-increment like generator, the tableIdx argument could ignored. // For example, this function use the Snowflake library to generate the primary key. // // func(tableIdx int64) int64 { // return nodes[tableIdx].Generate().Int64() // } PrimaryKeyGeneratorFn func(tableIdx int64) int64 // contains filtered or unexported fields }
Config specifies the configuration for sharding.
type ConnPool ¶
ConnPool Implement a ConnPool for replace db.Statement.ConnPool in Gorm
func (ConnPool) ExecContext ¶
func (ConnPool) PrepareContext ¶
func (ConnPool) QueryContext ¶
func (pool ConnPool) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
https://github.com/go-gorm/gorm/blob/v1.21.11/callbacks/query.go#L18
func (ConnPool) QueryRowContext ¶
type Sharding ¶
func (*Sharding) Initialize ¶
Initialize implement for Gorm plugin interface
Click to show internal directories.
Click to hide internal directories.