Skip to content

Refactor Config API same as dbresolver #2

Closed
@huacnlee

Description

@huacnlee
db.Use(sharding.Register(sharding.Config{
		ShardingKey: "user_id",
		ShardingAlgorithm: func(value interface{}) (suffix string, err error) {
				if uid, ok := value.(int64); ok {
						return fmt.Sprintf("_%02d", uid%4), nil
				}
				return "", errors.New("invalid user_id")
		},
		PrimaryKeyGenerate: func(tableIdx int64) interface{} {
				// use Built in keygen for generate a sequence primary key with table index
				return keygen.Next(tableIdx)
		}
}, "orders").Register(sharding.Config{
		ShardingKey: "user_id",
		ShardingAlgorithm: func(value interface{}) (suffix string, err error) {
				if uid, ok := value.(int64); ok {
						return fmt.Sprintf("_%02d", uid%4), nil
				}
				return "", errors.New("invalid user_id")
		},
		PrimaryKeyGenerate: func(tableIdx int64) interface{} {
				return uuid.UUID()
		}
		// This case for show up give notifications, activities table use same sharding rule.
}, Notification{}, Acitivity{}))

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions