コード例 #1
0
ファイル: cachegoroutine.go プロジェクト: matm/gobuild
func test(engine *xorm.Engine) {
	err := engine.CreateTables(u)
	if err != nil {
		fmt.Println(err)
		return
	}

	size := 500
	queue := make(chan int, size)

	for i := 0; i < size; i++ {
		go func(x int) {
			//x := i
			err := engine.Ping()
			if err != nil {
				fmt.Println(err)
			} else {
				for j := 0; j < 10; j++ {
					if x+j < 2 {
						_, err = engine.Get(u)
					} else if x+j < 4 {
						users := make([]User, 0)
						err = engine.Find(&users)
					} else if x+j < 8 {
						_, err = engine.Count(u)
					} else if x+j < 16 {
						_, err = engine.Insert(&User{Name: "xlw"})
					} else if x+j < 32 {
						//_, err = engine.Id(1).Delete(u)
						_, err = engine.Delete(u)
					}
					if err != nil {
						fmt.Println(err)
						queue <- x
						return
					}
				}
				fmt.Printf("%v success!\n", x)
			}
			queue <- x
		}(i)
	}

	for i := 0; i < size; i++ {
		<-queue
	}

	//conns := atomic.LoadInt32(&xorm.ConnectionNum)
	//fmt.Println("connection number:", conns)
	fmt.Println("end")
}
コード例 #2
0
func main() {
	var (
		engine *xorm.Engine
		user   *User
	)

	engine = SetupDb()

	//START CODE OMIT
	engine.Insert(&User{Id: 1, FirstName: "John", LastName: "Doe"})
	PrintTable(engine)

	user = &User{Id: 1}
	engine.Get(user)

	user.FirstName = "James"
	engine.Update(user)
	PrintTable(engine)

	engine.Delete(user)
	PrintTable(engine)
	//END CODE OMIT
}