- 在配置文件中配置是否分库分表, shard key为表的主键, 必须为int64类型
- 使用modulo算法通过shard key定位shard数据库
- 生成
GetByShardKey()
代码以方便查询 - 使用
CreateShards()
代码方便建立shard connection - 可连接protoconf
[mysql]
dbname = "test"
host = "localhost"
port = 3306
user = "root"
pass = "root"
sslmode = "false"
sharding = true
// create shards group
boil.CreateShards("root:root@/books_shard_1?parseTime=true", "root:root@/books_shard_2?parseTime=true")
// find a book with sharding_key:id = 1
book, _ := models.BooksMgr.GetByID(1)