Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 700 Bytes

分库分表.md

File metadata and controls

32 lines (24 loc) · 700 Bytes

分库分表

  • 在配置文件中配置是否分库分表, 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)