Documentation ¶
Index ¶
- 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 ¶
This section is empty.
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 // 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 LongKey library to generate the suffix. // // func(id int64) (suffix string) { // return fmt.Sprintf("_%02d", longkey.TableIdx(id)) // } ShardingAlgorithmByPrimaryKey func(id int64) (suffix string) // PrimaryKeyGenerate specifies a function to generate the primary key. // Used only when insert and the record does not contains an id field. // We recommend you use the // [LongKey](https://github.com/longbridgeapp/longkey) component, // it is a distributed primary key generator. // When use auto-increment like generator, the tableIdx argument could ignored. // // For example, this function use the LongKey library to generate the primary key. // // func(tableIdx int64) int64 { // return longkey.Next(tableIdx) // } PrimaryKeyGenerate func(tableIdx int64) int64 }
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.