Skip to content

Commit 6f08813

Browse files
committed
Merge branch 'release/v1.3.1'
2 parents ff457ca + 0875f2a commit 6f08813

File tree

8 files changed

+93
-8
lines changed

8 files changed

+93
-8
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## v1.3.1 - 2015-01-22
6+
7+
### Added
8+
- Added more documentation and examples for `GetAll`.
9+
10+
### Fixed
11+
- Fixed `RunWrite` not defering its call to `Cursor.Close()`. This could cause issues if an error occurred when decoding the result.
12+
- Fixed panic when calling `Error()` on a GoRethink `rqlError`.
13+
514
## v1.3.0 - 2016-01-11
615

716
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
![GoRethink Logo](https://raw.github.com/wiki/dancannon/gorethink/gopher-and-thinker-s.png "Golang Gopher and RethinkDB Thinker")
1010

11-
Current version: v1.3.0 (RethinkDB v2.2)
11+
Current version: v1.3.1 (RethinkDB v2.2)
1212

1313
Please note that this version of the driver only supports versions of RethinkDB using the v0.4 protocol (any versions of the driver older than RethinkDB 2.0 will not work).
1414

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Package gorethink implements a Go driver for RethinkDB
22
//
3-
// Current version: v1.3.0 (RethinkDB v2.2)
3+
// Current version: v1.3.1 (RethinkDB v2.2)
44
// For more in depth information on how to use RethinkDB check out the API docs
55
// at http://rethinkdb.com/api
66
package gorethink

errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (e rqlServerError) String() string {
9797
type rqlError string
9898

9999
func (e rqlError) Error() string {
100-
return fmt.Sprintf("gorethink: %s", e)
100+
return fmt.Sprintf("gorethink: %s", string(e))
101101
}
102102

103103
func (e rqlError) String() string {

example_query_select_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,79 @@ func ExampleTerm_Get() {
3030
// Output: Superman
3131
}
3232

33+
// Find a document by ID.
34+
func ExampleTerm_GetAll() {
35+
// Fetch the row from the database
36+
res, err := DB("examples").Table("heroes").GetAll(2).Run(session)
37+
if err != nil {
38+
fmt.Print(err)
39+
return
40+
}
41+
defer res.Close()
42+
43+
if res.IsNil() {
44+
fmt.Print("Row not found")
45+
return
46+
}
47+
48+
var hero map[string]interface{}
49+
err = res.One(&hero)
50+
if err != nil {
51+
fmt.Printf("Error scanning database result: %s", err)
52+
return
53+
}
54+
fmt.Print(hero["name"])
55+
56+
// Output: Superman
57+
}
58+
59+
// Find a document by ID.
60+
func ExampleTerm_GetAll_multiple() {
61+
// Fetch the row from the database
62+
res, err := DB("examples").Table("heroes").GetAll(1, 2).Run(session)
63+
if err != nil {
64+
fmt.Print(err)
65+
return
66+
}
67+
defer res.Close()
68+
69+
var heroes []map[string]interface{}
70+
err = res.All(&heroes)
71+
if err != nil {
72+
fmt.Printf("Error scanning database result: %s", err)
73+
return
74+
}
75+
fmt.Print(heroes[0]["name"])
76+
77+
// Output: Superman
78+
}
79+
80+
// Find all document with an indexed value.
81+
func ExampleTerm_GetAllByIndex() {
82+
// Fetch the row from the database
83+
res, err := DB("examples").Table("heroes").GetAllByIndex("code_name", "man_of_steel").Run(session)
84+
if err != nil {
85+
fmt.Print(err)
86+
return
87+
}
88+
defer res.Close()
89+
90+
if res.IsNil() {
91+
fmt.Print("Row not found")
92+
return
93+
}
94+
95+
var hero map[string]interface{}
96+
err = res.One(&hero)
97+
if err != nil {
98+
fmt.Printf("Error scanning database result: %s", err)
99+
return
100+
}
101+
fmt.Print(hero["name"])
102+
103+
// Output: Superman
104+
}
105+
33106
// Find a document and merge another document with it.
34107
func ExampleTerm_Get_merge() {
35108
// Fetch the row from the database

query.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,12 @@ func (t Term) RunWrite(s *Session, optArgs ...RunOpts) (WriteResponse, error) {
253253
if err != nil {
254254
return response, err
255255
}
256+
defer res.Close()
256257

257258
if err = res.One(&response); err != nil {
258259
return response, err
259260
}
260261

261-
if err = res.Close(); err != nil {
262-
return response, err
263-
}
264-
265262
if response.Errors > 0 {
266263
return response, fmt.Errorf(response.FirstError)
267264
}

query_select.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ func (t Term) Get(args ...interface{}) Term {
6161
return constructMethodTerm(t, "Get", p.Term_GET, args, map[string]interface{}{})
6262
}
6363

64-
// GetAll gets all documents where the given value matches the value of the primary index.
64+
// GetAll gets all documents where the given value matches the value of the primary
65+
// index. Multiple values can be passed this function if you want to select multiple
66+
// documents. If the documents you are fetching have composite keys then each
67+
// argument should be a slice. For more information see the examples.
6568
func (t Term) GetAll(keys ...interface{}) Term {
6669
return constructMethodTerm(t, "GetAll", p.Term_GET_ALL, keys, map[string]interface{}{})
6770
}

testdata_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func setupTestData() {
2424
[]interface{}{Row.Field("date"), Row.Field("title")},
2525
).Exec(session)
2626

27+
DB("examples").Table("heroes").IndexCreate("code_name").Exec(session)
28+
DB("examples").Table("heroes").IndexWait().Exec(session)
29+
2730
DB("examples").Table("games").IndexCreate("type").Exec(session)
2831
DB("examples").Table("games").IndexWait().Exec(session)
2932

0 commit comments

Comments
 (0)