Skip to content

Instantly share code, notes, and snippets.

@yutakahashi114
Created January 19, 2020 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutakahashi114/63073d867d693e8900e45b91c3eff918 to your computer and use it in GitHub Desktop.
Save yutakahashi114/63073d867d693e8900e45b91c3eff918 to your computer and use it in GitHub Desktop.
func read(engine *xorm.Engine) {
t := time.Date(2020, 1, 1, 0, 0, 0, 0, time.Local)
// 1件取得
u := user{}
has, err := engine.
Where("id = ?", id).
Where("last_name LIKE ?", "テスト").
In("last_name", "テスト", "テスト2").
In("last_name", []string{"テスト", "テスト2"}).
Where("first_name = ? OR first_name = ?", "太郎", "太郎2").
Where("created_at >= ?", t).
Get(&u)
if err != nil {
log.Println(err)
return
}
if !has {
log.Println("Not Found")
return
}
// 複数取得
us := []user{}
err = engine.
Limit(10, 10).
Asc("id", "first_name").
Desc("last_name").
Find(&us)
if err != nil {
log.Println(err)
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment