Exemplo n.º 1
0
func ExampleRegisterShardedDatabase() {
	engine1, _ = xorm.NewEngine("mysql", "root:@/example_user_a?charset=utf8")
	engine2, _ = xorm.NewEngine("mysql", "root:@/example_user_a?charset=utf8")
	engine3, _ = xorm.NewEngine("mysql", "root:@/example_user_b?charset=utf8")
	engine4, _ = xorm.NewEngine("mysql", "root:@/example_user_b?charset=utf8")

	w = wizard.NewWizard()
	shardClusters := w.CreateShardCluster(&User{}, 997) // create shard clusters for User{} with slotsize 997
	standardClusterA := wizard.NewCluster(engine1)
	standardClusterA.RegisterSlave(engine2)
	shardClusters.RegisterShard(0, 500, standardClusterA)

	standardClusterB := wizard.NewCluster(engine3)
	standardClusterB.RegisterSlave(engine4)
	shardClusters.RegisterShard(501, 996, standardClusterB)
}
Exemplo n.º 2
0
func testCreateWizard() *wizard.Wizard {
	wiz := wizard.NewWizard()

	userShards := wiz.CreateShardCluster(testUser{}, 997)
	shard01 := wizard.NewCluster(dbUser01Master)
	shard01.RegisterSlave(dbUser01Slave01)
	shard01.RegisterSlave(dbUser01Slave02)
	userShards.RegisterShard(0, 499, shard01) // user A

	shard02 := wizard.NewCluster(dbUser02Master)
	shard02.RegisterSlave(dbUser02Slave01)
	shard02.RegisterSlave(dbUser02Slave02)
	userShards.RegisterShard(500, 996, shard02) // user B

	foobarCluster := wiz.CreateCluster(testFoobar{}, dbFoobarMaster)
	foobarCluster.RegisterSlave(dbFoobarSlave01)
	foobarCluster.RegisterSlave(dbFoobarSlave02)

	otherCluster := wizard.NewCluster(dbOther)
	wiz.SetDefault(otherCluster)
	return wiz
}
Exemplo n.º 3
0
func ExampleRegisterStandardDatabases() {
	engine1, _ = xorm.NewEngine("mysql", "root:@/example_user?charset=utf8")
	engine2, _ = xorm.NewEngine("mysql", "root:@/example_user?charset=utf8")
	engine3, _ = xorm.NewEngine("mysql", "root:@/example_foobar?charset=utf8")
	engine4, _ = xorm.NewEngine("mysql", "root:@/example_other?charset=utf8")

	w = wizard.NewWizard()
	stndardCluster := w.CreateCluster(User{}, engine1) // engine is master database used for table of User{}
	stndardCluster.RegisterSlave(engine2)              // add slave

	_ = w.CreateCluster("foobar", engine3) // engine3 is master database used for table of foobar

	stndardCluster = wizard.NewCluster(engine4)
	w.SetDefault(stndardCluster) // engine4 is master database used for all the other tables
}