-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
85 lines (70 loc) · 1.66 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package tyr
import (
"fmt"
"time"
)
func ExampleSelect() {
Select("title", "body").
From("suggestions").
OrderBy("id").
Limit(10)
}
func ExampleSelectStmt_Where() {
ids := []int64{1, 2, 3, 4, 5}
Select("*").From("suggestions").Where("id IN ?", ids)
}
func ExampleSelectStmt_Join() {
Select("*").From("suggestions").
Join("subdomains", "suggestions.subdomain_id = subdomains.id")
Select("*").From("suggestions").
LeftJoin("subdomains", "suggestions.subdomain_id = subdomains.id")
// join multiple tables
Select("*").From("suggestions").
Join("subdomains", "suggestions.subdomain_id = subdomains.id").
Join("accounts", "subdomains.accounts_id = accounts.id")
}
func ExampleSelectBySql() {
SelectBySql("SELECT `title`, `body` FROM `suggestions` ORDER BY `id` ASC LIMIT 10")
}
func ExampleDeleteStmt() {
DeleteFrom("suggestions").Where("id = ?", 1)
}
func ExampleAnd() {
And(
Or(
Gt("created_at", "2015-09-10"),
Lte("created_at", "2015-09-11"),
),
Eq("title", "hello world"),
)
}
func ExampleI() {
// I, identifier, can be used to quote.
I("suggestions.id").As("id") // `suggestions`.`id`
}
func ExampleSelectStmt_As() {
Select("count(id)").From(
Select("*").From("suggestions").As("count"),
)
}
func ExampleInsertStmt_Pair() {
InsertInto("suggestions").
Pair("title", "Gopher").
Pair("body", "I love go.")
}
func ExampleInsertStmt_Record() {
type Suggestion struct {
ID int64
Title NullString
CreatedAt time.Time
}
sugg := &Suggestion{
Title: NewNullString("Gopher"),
CreatedAt: time.Now(),
}
InsertInto("suggestions").
Columns("title").
Record(&sugg)
// id is set automatically
fmt.Println(sugg.ID)
}