Sharding 分片配置实例
shardingRule:tables:t_order:actualDataNodes: ds${0..1}.t_order${0..1}databaseStrategy:inline:shardingColumn: user_idalgorithmExpression: ds${user_id % 2}tableStrategy: inline:shardingColumn: order_idalgorithmExpression: t_order${order_id % 2}keyGenerator:type: SNOWFLAKEcolumn: order_idt_order_item:actualDataNodes: ds${0..1}.t_order_item${0..1}databaseStrategy:inline:shardingColumn: user_idalgorithmExpression: ds${user_id % 2}tableStrategy:inline:shardingColumn: order_idalgorithmExpression: t_order_item${order_id % 2}keyGenerator:type: SNOWFLAKEcolumn: order_item_idbindingTables:- t_order,t_order_itemdefaultTableStrategy:none:
才两张表就那么多,是不是感觉,太复杂了!
来种简单的吧.
bee.db.sharding[0].baseTableName=orders
#设置表对应的Class类也可以(要包括包名)
#bee.db.sharding[0].className=org.teasoft.exam.Orders
bee.db.sharding[0].fullNodes=ds[0..1].orders[0..5]
#用于分片的表字段.
bee.db.sharding[0].tabField=orderid
主从表,使用同样的规则,即可在同一库中查询.
对于的Java风格配置:
ShardingConfig.addShardingBean("orders",new ShardingBean("ds[0..1].orders[0..5]", "orderid"));
来后两种就是ORM Bee的,感觉如何.
可下载源码.
ORM Bee, 除了传统ORM功能,还具有 MongoDB ORM, Android ORM, Sharding JDBC 等功能.