當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Engine.Insert方法代碼示例

本文整理匯總了Golang中github.com/lunny/xorm.Engine.Insert方法的典型用法代碼示例。如果您正苦於以下問題:Golang Engine.Insert方法的具體用法?Golang Engine.Insert怎麽用?Golang Engine.Insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/lunny/xorm.Engine的用法示例。


在下文中一共展示了Engine.Insert方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Crawl

func Crawl(engine *xorm.Engine) error {
	latestIndices, err := getLatestIndices()
	if err != nil {
		return err
	}

	_, err = engine.Insert(&latestIndices.News)
	if err != nil {
		return err
	}

	news := make([]News, 0)
	for _, newsIndex := range latestIndices.News {
		content, err := getArticle(newsIndex.Id)
		if err == nil {
			news = append(news, News{newsIndex.Id, content})
		}
	}
	_, err = engine.Insert(&news)
	if err != nil {
		return err
	}

	return nil
}
開發者ID:ZCLanner,項目名稱:WebZhihuNews,代碼行數:25,代碼來源:crawl_news.go

示例2: test

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.Test()
			if err != nil {
				fmt.Println(err)
			} else {
				err = engine.Map(u)
				if err != nil {
					fmt.Println("Map user failed")
				} 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)
						}
						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")
}
開發者ID:matm,項目名稱:gobuild,代碼行數:55,代碼來源:goroutine.go

示例3: test

func test(engine *xorm.Engine) {
	err := engine.CreateTables(u)
	if err != nil {
		fmt.Println(err)
		return
	}

	engine.ShowSQL = true
	engine.Pool.SetMaxConns(5)
	size := 1000
	queue := make(chan int, size)

	for i := 0; i < size; i++ {
		go func(x int) {
			//x := i
			err := engine.Test()
			if err != nil {
				fmt.Println(err)
			} else {
				err = engine.Map(u)
				if err != nil {
					fmt.Println("Map user failed")
				} 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)
						}
						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
	}

	fmt.Println("end")
}
開發者ID:jimmykuu,項目名稱:xorm,代碼行數:55,代碼來源:maxconnect.go

示例4: main

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
}
開發者ID:GoSteelProgrammers,項目名稱:talk-review-orms,代碼行數:23,代碼來源:crud.go

示例5: main

func main() {
	var (
		engine *xorm.Engine
	)

	engine = SetupDb()

	engine.Insert(&User{
		Id:        1,
		FirstName: "John",
		LastName:  "Doe",
		Age:       24,
	})

	engine.Insert(&User{
		Id:        2,
		FirstName: "Jane",
		LastName:  "Doe",
		Age:       52,
	})

	engine.Insert(&User{
		Id:        3,
		FirstName: "Joe",
		LastName:  "Shmoe",
		Age:       10,
	})

	//START CODE OMIT

	var users []User
	engine.Where("last_name = ? OR age < ?", "Doe", "12").OrderBy("age").Limit(2).Find(&users)
	fmt.Printf("%+v\n", users)

	//END CODE OMIT
}
開發者ID:GoSteelProgrammers,項目名稱:talk-review-orms,代碼行數:36,代碼來源:query.go


注:本文中的github.com/lunny/xorm.Engine.Insert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。