forked from rethinkdb/rethinkdb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_write_test.go
99 lines (82 loc) · 2.51 KB
/
query_write_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
package gorethink
import (
test "gopkg.in/check.v1"
)
func (s *RethinkSuite) TestWriteInsert(c *test.C) {
query := Db("test").Table("test").Insert(map[string]interface{}{"num": 1})
_, err := query.Run(sess)
c.Assert(err, test.IsNil)
}
func (s *RethinkSuite) TestWriteInsertChanges(c *test.C) {
query := Db("test").Table("test").Insert([]interface{}{
map[string]interface{}{"num": 1},
map[string]interface{}{"num": 2},
}, InsertOpts{ReturnChanges: true})
res, err := query.RunWrite(sess)
c.Assert(err, test.IsNil)
c.Assert(res.Inserted, test.Equals, 2)
c.Assert(len(res.Changes), test.Equals, 2)
}
func (s *RethinkSuite) TestWriteInsertStruct(c *test.C) {
var response map[string]interface{}
o := object{
Name: "map[string]interface{}ect 3",
Attrs: []attr{
attr{
Name: "Attr 2",
Value: "Value",
},
},
}
query := Db("test").Table("test").Insert(o)
res, err := query.Run(sess)
c.Assert(err, test.IsNil)
err = res.One(&response)
c.Assert(err, test.IsNil)
c.Assert(response["inserted"], test.Equals, float64(1))
}
func (s *RethinkSuite) TestWriteInsertStructPointer(c *test.C) {
var response map[string]interface{}
o := object{
Name: "map[string]interface{}ect 3",
Attrs: []attr{
attr{
Name: "Attr 2",
Value: "Value",
},
},
}
query := Db("test").Table("test").Insert(&o)
res, err := query.Run(sess)
c.Assert(err, test.IsNil)
err = res.One(&response)
c.Assert(err, test.IsNil)
c.Assert(response["inserted"], test.Equals, float64(1))
}
func (s *RethinkSuite) TestWriteUpdate(c *test.C) {
query := Db("test").Table("test").Insert(map[string]interface{}{"num": 1})
_, err := query.Run(sess)
c.Assert(err, test.IsNil)
// Update the first row in the table
query = Db("test").Table("test").Sample(1).Update(map[string]interface{}{"num": 2})
_, err = query.Run(sess)
c.Assert(err, test.IsNil)
}
func (s *RethinkSuite) TestWriteReplace(c *test.C) {
query := Db("test").Table("test").Insert(map[string]interface{}{"num": 1})
_, err := query.Run(sess)
c.Assert(err, test.IsNil)
// Replace the first row in the table
query = Db("test").Table("test").Sample(1).Update(map[string]interface{}{"num": 2})
_, err = query.Run(sess)
c.Assert(err, test.IsNil)
}
func (s *RethinkSuite) TestWriteDelete(c *test.C) {
query := Db("test").Table("test").Insert(map[string]interface{}{"num": 1})
_, err := query.Run(sess)
c.Assert(err, test.IsNil)
// Delete the first row in the table
query = Db("test").Table("test").Sample(1).Delete()
_, err = query.Run(sess)
c.Assert(err, test.IsNil)
}