Created
January 19, 2020 13:17
-
-
Save yutakahashi114/63073d867d693e8900e45b91c3eff918 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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