forked from rethinkdb/rethinkdb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testdata_test.go
107 lines (97 loc) · 3.17 KB
/
testdata_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package gorethink
func setupTestData() {
// Delete any preexisting databases
DBDrop("test").Exec(session)
DBDrop("examples").Exec(session)
DBDrop("superheroes").Exec(session)
DBCreate("test").Exec(session)
DBCreate("examples").Exec(session)
DB("examples").TableCreate("posts").Exec(session)
DB("examples").TableCreate("heroes").Exec(session)
DB("examples").TableCreate("users").Exec(session)
DB("examples").TableCreate("games").Exec(session)
DB("examples").TableCreate("games2").Exec(session)
DB("examples").TableCreate("marvel").Exec(session)
DB("examples").Table("posts").IndexCreate("date").Exec(session)
DB("examples").Table("posts").IndexWait().Exec(session)
DB("examples").Table("posts").IndexCreateFunc(
"dateAndTitle",
[]interface{}{Row.Field("date"), Row.Field("title")},
).Exec(session)
DB("examples").Table("games").IndexCreate("type").Exec(session)
DB("examples").Table("games").IndexWait().Exec(session)
// Create heroes table
DB("examples").Table("heroes").Insert([]interface{}{
map[string]interface{}{
"id": 1,
"code_name": "batman",
"name": "Batman",
},
map[string]interface{}{
"id": 2,
"code_name": "man_of_steel",
"name": "Superman",
},
map[string]interface{}{
"id": 3,
"code_name": "ant_man",
"name": "Ant Man",
},
map[string]interface{}{
"id": 4,
"code_name": "flash",
"name": "The Flash",
},
}).Exec(session)
// Create users table
DB("examples").Table("users").Insert([]interface{}{
map[string]interface{}{
"id": "william",
"email": "[email protected]",
"age": 30,
},
map[string]interface{}{
"id": "lara",
"email": "[email protected]",
"age": 30,
},
map[string]interface{}{
"id": "john",
"email": "[email protected]",
"age": 19,
},
map[string]interface{}{
"id": "jane",
"email": "[email protected]",
"age": 45,
},
map[string]interface{}{
"id": "bob",
"email": "[email protected]",
"age": 24,
},
map[string]interface{}{
"id": "brad",
"email": "[email protected]",
"age": 15,
},
}).Exec(session)
// Create games table
DB("examples").Table("games").Insert([]interface{}{
map[string]interface{}{"id": 2, "player": "Bob", "points": 15, "type": "ranked"},
map[string]interface{}{"id": 5, "player": "Alice", "points": 7, "type": "free"},
map[string]interface{}{"id": 11, "player": "Bob", "points": 10, "type": "free"},
map[string]interface{}{"id": 12, "player": "Alice", "points": 2, "type": "free"},
}).Exec(session)
// Create games2 table
DB("examples").Table("games2").Insert([]interface{}{
map[string]interface{}{"id": 1, "matches": map[string]interface{}{"a": []int{1, 2, 3}, "b": []int{4, 5, 6}}},
map[string]interface{}{"id": 2, "matches": map[string]interface{}{"b": []int{100}, "c": []int{7, 8, 9}}},
map[string]interface{}{"id": 3, "matches": map[string]interface{}{"a": []int{10, 20}, "c": []int{70, 80}}},
}).Exec(session)
// Create marvel table
DB("examples").Table("marvel").Insert([]interface{}{
map[string]interface{}{"name": "Iron Man", "victories": 214},
map[string]interface{}{"name": "Jubilee", "victories": 9},
}).Exec(session)
}