Skip to content

Commit ab7bf69

Browse files
committed
Merge branch 'hotfix/v0.3.2'
2 parents 7121b08 + 6d57a48 commit ab7bf69

File tree

11 files changed

+112
-15
lines changed

11 files changed

+112
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v0.3.2 - 17 Aug 2014
4+
5+
- Fixed issue causing connections not to be closed correctly (#109)
6+
- Fixed issue causing terms in optional arguments to be encoded incorrectly (#114)
7+
38
## v0.3.1 - 14 June 2014
49

510
- Fixed "Token ## not in stream cache" error (#103)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ GoRethink - RethinkDB Driver for Go [![wercker status](https://app.wercker.com/s
44
[Go](http://golang.org/) driver for [RethinkDB](http://www.rethinkdb.com/) made by [Daniel Cannon](http://github.com/dancannon) and based off of Christopher Hesse's [RethinkGo](https://github.com/christopherhesse/rethinkgo) driver.
55

66

7-
Current version: v0.3.1 (RethinkDB v1.13)
7+
Current version: v0.3.2 (RethinkDB v1.13)
88

99
**Version 0.3 introduced some API changes, for more information check the [change log](CHANGELOG.md)**
1010

connection.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (c *Connection) SendQuery(s *Session, q *p.Query, t Term, opts map[string]i
252252
}
253253

254254
func (c *Connection) Close() error {
255-
err := c.s.noreplyWaitQuery()
255+
err := c.NoreplyWait()
256256
if err != nil {
257257
return err
258258
}
@@ -268,6 +268,23 @@ func (c *Connection) CloseNoWait() error {
268268
return c.Conn.Close()
269269
}
270270

271+
// noreplyWaitQuery sends the NOREPLY_WAIT query to the server.
272+
// TODO: Removed duplicated functions in connection and session
273+
// for NoReplyWait
274+
func (c *Connection) NoreplyWait() error {
275+
q := &p.Query{
276+
Type: p.Query_NOREPLY_WAIT.Enum(),
277+
Token: proto.Int64(c.s.nextToken()),
278+
}
279+
280+
_, err := c.SendQuery(c.s, q, Term{}, map[string]interface{}{}, false)
281+
if err != nil {
282+
return err
283+
}
284+
285+
return nil
286+
}
287+
271288
func checkErrorResponse(response *p.Response, t Term) error {
272289
switch response.GetType() {
273290
case p.Response_CLIENT_ERROR:

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Go driver for RethinkDB
22
//
3-
// Current version: v0.3.1 (RethinkDB v1.13)
3+
// Current version: v0.3.2 (RethinkDB v1.13)
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

encoding/encoder.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"reflect"
88
"runtime"
99
"sort"
10-
"time"
1110
)
1211

1312
// Encode returns the encoded value of v.
@@ -46,8 +45,14 @@ func encode(v reflect.Value) (reflect.Value, error) {
4645

4746
// Special cases
4847
// Time should not be encoded as it is handled by the Expr method
49-
if v.Type() == reflect.TypeOf(time.Time{}) {
50-
return v, nil
48+
for _, hook := range encodeHooks {
49+
success, ret, err := hook(v)
50+
if err != nil {
51+
return ret, err
52+
}
53+
if success {
54+
return ret, nil
55+
}
5156
}
5257

5358
switch v.Kind() {

encoding/encoding.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package encoding
2+
3+
import "reflect"
4+
5+
type EncodeHook func(src reflect.Value) (success bool, ret reflect.Value, err error)
6+
7+
var encodeHooks []EncodeHook
8+
9+
func init() {
10+
encodeHooks = []EncodeHook{}
11+
}
12+
13+
func RegisterEncodeHook(hook EncodeHook) {
14+
encodeHooks = append(encodeHooks, hook)
15+
}

query_control.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"reflect"
55
"time"
66

7-
"github.com/dancannon/gorethink/encoding"
87
p "github.com/dancannon/gorethink/ql2"
98
)
109

@@ -73,7 +72,7 @@ func expr(value interface{}, depth int) Term {
7372
return makeFunc(val)
7473
}
7574
if typ.Kind() == reflect.Struct {
76-
data, err := encoding.Encode(val)
75+
data, err := encode(val)
7776

7877
if err != nil || data == nil {
7978
return Term{

query_transformation_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,36 @@ func (s *RethinkSuite) TestTransformationOrderByIndex(c *test.C) {
142142
})
143143
}
144144

145+
func (s *RethinkSuite) TestTransformationOrderByIndexAsc(c *test.C) {
146+
Db("test").TableCreate("OrderByIndex").Exec(sess)
147+
Db("test").Table("test").IndexDrop("OrderByIndex").Exec(sess)
148+
149+
// Test database creation
150+
Db("test").Table("OrderByIndex").IndexCreateFunc("test", Row.Field("num")).Exec(sess)
151+
Db("test").Table("OrderByIndex").Insert(noDupNumObjList).Exec(sess)
152+
153+
query := Db("test").Table("OrderByIndex").OrderBy(OrderByOpts{
154+
Index: Asc("test"),
155+
})
156+
157+
var response []interface{}
158+
res, err := query.Run(sess)
159+
c.Assert(err, test.IsNil)
160+
161+
err = res.All(&response)
162+
163+
c.Assert(err, test.IsNil)
164+
c.Assert(response, JsonEquals, []interface{}{
165+
map[string]interface{}{"num": 0, "id": 1, "g2": 1, "g1": 1},
166+
map[string]interface{}{"num": 5, "id": 2, "g2": 2, "g1": 2},
167+
map[string]interface{}{"num": 10, "id": 3, "g2": 2, "g1": 3},
168+
map[string]interface{}{"num": 15, "id": 6, "g2": 1, "g1": 1},
169+
map[string]interface{}{"num": 25, "id": 9, "g2": 3, "g1": 2},
170+
map[string]interface{}{"num": 50, "id": 8, "g2": 2, "g1": 4},
171+
map[string]interface{}{"num": 100, "id": 5, "g2": 3, "g1": 2},
172+
})
173+
}
174+
145175
func (s *RethinkSuite) TestTransformationOrderByMultiple(c *test.C) {
146176
query := Expr(objList).OrderBy(Desc("num"), Asc("id"))
147177

results.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,21 @@ func (c *Cursor) One(result interface{}) error {
202202
if c.IsNil() {
203203
return ErrEmptyResult
204204
}
205+
206+
var err error
205207
ok := c.Next(result)
206208
if !ok {
207-
err := c.Err()
209+
err = c.Err()
208210
if err == nil {
209-
return ErrEmptyResult
211+
err = ErrEmptyResult
210212
}
211-
return err
212213
}
213214

214-
return c.Close()
215+
if e := c.Close(); e != nil {
216+
err = e
217+
}
218+
219+
return err
215220
}
216221

217222
// Tests if the current row is nil.

session.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,18 @@ func (s *Session) noreplyWaitQuery() error {
344344
}
345345

346346
conn := s.pool.Get()
347-
defer conn.Close()
348347

349348
_, err := conn.SendQuery(s, q, Term{}, map[string]interface{}{}, false)
349+
if err != nil {
350+
return err
351+
}
350352

351-
return err
353+
err = conn.Close()
354+
if err != nil {
355+
return err
356+
}
357+
358+
return nil
352359
}
353360

354361
func (s *Session) checkCache(token int64) (*Cursor, bool) {

0 commit comments

Comments
 (0)