Пример #1
0
func TestNew(t *testing.T) {
	assert := assert.New(t)
	wiz := wizard.NewWizard()

	orm := New(wiz)
	assert.Equal(wiz, orm.Wiz)
}
Пример #2
0
func TestSetIsAutoTransaction(t *testing.T) {
	assert := assert.New(t)
	wiz := wizard.NewWizard()

	orm := New(wiz)
	assert.False(orm.IsAutoTransaction())
	orm.SetAutoTransaction(true)
	assert.True(orm.IsAutoTransaction())
	orm.SetAutoTransaction(false)
	assert.False(orm.IsAutoTransaction())
}
Пример #3
0
func TestIsReadOnly(t *testing.T) {
	assert := assert.New(t)
	wiz := wizard.NewWizard()

	orm := New(wiz)
	assert.False(orm.IsReadOnly())
	orm.ReadOnly(true)
	assert.True(orm.IsReadOnly())
	orm.ReadOnly(false)
	assert.False(orm.IsReadOnly())
}
Пример #4
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
}
Пример #5
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)
}
Пример #6
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
}
Пример #7
0
func init() {
	initTestDB()
	emptyWiz = wizard.NewWizard()
}