Skip to content

Commit 148a64d

Browse files
committed
Merge branch 'release/v0.2'
2 parents 9037954 + 665bc47 commit 148a64d

16 files changed

+245
-131
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# Changelog
22

3-
## V1.11 - 27 November 2013
3+
## v0.2 (RethinkDB v1.12) - 13 April
4+
5+
* Changed `Connect` to use `ConnectOpts` instead of `map[string]interface{}`
6+
* Migrated to new `Group`/`Ungroup` functions, these replace `GroupedMapReduce` and `GroupBy`
7+
* Added new aggregators
8+
* Removed base parameter for `Reduce`
9+
* Added `Object` function
10+
* Added `Upcase`, `Downcase` and `Split` string functions
11+
* Added `GROUPED_DATA` pseudotype
12+
* Fixed query printing
13+
14+
## v0.1 (RethinkDB v1.11) - 27 November 2013
415

516
* Added noreply writes
617
* Added the new terms `index_status`, `index_wait` and `sync`

README.md

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
# GoRethink - RethinkDB Driver for Go
2-
3-
[![wercker status](https://app.wercker.com/status/e315e764041af8e80f0c68280d4b4de2/m "wercker status")](https://app.wercker.com/project/bykey/e315e764041af8e80f0c68280d4b4de2)
1+
GoRethink - RethinkDB Driver for Go [![wercker status](https://app.wercker.com/status/e315e764041af8e80f0c68280d4b4de2/s/master "wercker status")](https://app.wercker.com/project/bykey/e315e764041af8e80f0c68280d4b4de2) [![GoDoc](https://godoc.org/github.com/dancannon/gorethink?status.png)](https://godoc.org/github.com/dancannon/gorethink)
2+
=====================
43

54
[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.
65

7-
Current supported RethinkDB version: 1.11 | Documentation: [GoDoc](http://godoc.org/github.com/dancannon/gorethink)
6+
Current version: v0.2 (RethinkDB v1.12)
7+
8+
**Version 0.2 introduced some BC breaking changes, for more information check the [change log](CHANGELOG.md)**
89

910
## Installation
1011

1112
```sh
1213
go get -u github.com/dancannon/gorethink
1314
```
1415

15-
If you do not have the [goprotobuf](https://code.google.com/p/goprotobuf/) runtime installed, it is required:
16-
17-
```sh
18-
brew install mercurial # if you do not have mercurial installed
19-
go get code.google.com/p/goprotobuf/{proto,protoc-gen-go}
20-
```
21-
2216
## Connection
2317

2418
### Basic Connection
@@ -32,15 +26,14 @@ import (
3226

3327
var session *r.Session
3428

35-
session, err := r.Connect(map[string]interface{}{
36-
"address": "localhost:28015",
37-
"database": "test",
38-
"authkey": "14daak1cad13dj",
39-
})
29+
session, err := r.Connect(r.ConnectOpts{
30+
Address: "localhost:28015",
31+
Database: "test",
32+
})
4033

41-
if err != nil {
42-
log.Fatalln(err.Error())
43-
}
34+
if err != nil {
35+
log.Fatalln(err.Error())
36+
}
4437

4538
```
4639
See the [documentation](http://godoc.org/github.com/dancannon/gorethink#Connect) for a list of supported arguments to Connect().
@@ -56,16 +49,16 @@ import (
5649

5750
var session *r.Session
5851

59-
session, err := r.Connect(map[string]interface{}{
60-
"address": "localhost:28015",
61-
"database": "test",
62-
"maxIdle": 10,
63-
"idleTimeout": time.Second * 10,
64-
})
52+
session, err := r.Connect(r.ConnectOpts{
53+
Address: "localhost:28015",
54+
Database: "test",
55+
MaxIdle: 10,
56+
IdleTimeout: time.Second * 10,
57+
})
6558

66-
if err != nil {
67-
log.Fatalln(err.Error())
68-
}
59+
if err != nil {
60+
log.Fatalln(err.Error())
61+
}
6962
```
7063

7164
A pre-configured [Pool](http://godoc.org/github.com/dancannon/gorethink#Pool) instance can also be passed to Connect().

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 supported RethinkDB version: 1.11
3+
// Current version: v0.2 (RethinkDB v1.12)
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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,50 @@
11
package gorethink
22

33
import (
4+
"bytes"
45
"fmt"
6+
57
p "github.com/dancannon/gorethink/ql2"
68
)
79

10+
func printCarrots(t RqlTerm, frames []*p.Frame) string {
11+
var frame *p.Frame
12+
if len(frames) > 1 {
13+
frame, frames = frames[0], frames[1:]
14+
} else if len(frames) == 1 {
15+
frame, frames = frames[0], []*p.Frame{}
16+
}
17+
18+
for i, arg := range t.args {
19+
if frame.GetPos() == int64(i) {
20+
t.args[i] = RqlTerm{
21+
termType: p.Term_DATUM,
22+
data: printCarrots(arg, frames),
23+
}
24+
}
25+
}
26+
27+
for k, arg := range t.optArgs {
28+
if frame.GetOpt() == k {
29+
t.optArgs[k] = RqlTerm{
30+
termType: p.Term_DATUM,
31+
data: printCarrots(arg, frames),
32+
}
33+
}
34+
}
35+
36+
b := &bytes.Buffer{}
37+
for _, c := range t.String() {
38+
if c != '^' {
39+
b.WriteString(" ")
40+
} else {
41+
b.WriteString("^")
42+
}
43+
}
44+
45+
return b.String()
46+
}
47+
848
// Connection/Response errors
949
// ----------------------------------------------------------------------------
1050
type rqlResponseError struct {

example_query_select_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func ExampleRqlTerm_Get() {
1515
Gender string `gorethink:"gender"`
1616
}
1717

18-
sess, err := r.Connect(map[string]interface{}{
19-
"address": url,
18+
sess, err := r.Connect(r.ConnectOpts{
19+
Address: url,
2020
})
2121

2222
// Setup table
@@ -54,8 +54,8 @@ func ExampleRqlTerm_GetAll_compound() {
5454
Gender string `gorethink:"gender"`
5555
}
5656

57-
sess, err := r.Connect(map[string]interface{}{
58-
"address": url,
57+
sess, err := r.Connect(r.ConnectOpts{
58+
Address: url,
5959
})
6060

6161
// Setup table

example_query_table_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package gorethink_test
22

33
import (
44
"fmt"
5-
r "github.com/dancannon/gorethink"
65
"log"
6+
7+
r "github.com/dancannon/gorethink"
78
)
89

910
func ExampleRqlTerm_TableCreate() {
10-
sess, err := r.Connect(map[string]interface{}{
11-
"address": url,
11+
sess, err := r.Connect(r.ConnectOpts{
12+
Address: url,
1213
})
1314

1415
// Setup database
@@ -26,8 +27,8 @@ func ExampleRqlTerm_TableCreate() {
2627
}
2728

2829
func ExampleRqlTerm_IndexCreate() {
29-
sess, err := r.Connect(map[string]interface{}{
30-
"address": url,
30+
sess, err := r.Connect(r.ConnectOpts{
31+
Address: url,
3132
})
3233

3334
// Setup database
@@ -46,8 +47,8 @@ func ExampleRqlTerm_IndexCreate() {
4647
}
4748

4849
func ExampleRqlTerm_IndexCreate_compound() {
49-
sess, err := r.Connect(map[string]interface{}{
50-
"address": url,
50+
sess, err := r.Connect(r.ConnectOpts{
51+
Address: url,
5152
})
5253

5354
// Setup database

example_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package gorethink_test
22

33
import (
44
"fmt"
5-
r "github.com/dancannon/gorethink"
65
"log"
76
"os"
7+
8+
r "github.com/dancannon/gorethink"
89
)
910

1011
var session *r.Session
@@ -19,8 +20,8 @@ func init() {
1920
}
2021

2122
func Example() {
22-
session, err := r.Connect(map[string]interface{}{
23-
"address": url,
23+
session, err := r.Connect(r.ConnectOpts{
24+
Address: url,
2425
})
2526
if err != nil {
2627
log.Fatalln(err.Error())

gorethink_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package gorethink
33
import (
44
"encoding/json"
55
"flag"
6-
test "launchpad.net/gocheck"
76
"os"
87
"testing"
98
"time"
9+
10+
test "launchpad.net/gocheck"
1011
)
1112

1213
var sess *Session
@@ -37,10 +38,10 @@ var _ = test.Suite(&RethinkSuite{})
3738

3839
func (s *RethinkSuite) SetUpSuite(c *test.C) {
3940
var err error
40-
sess, err = Connect(map[string]interface{}{
41-
"address": url,
42-
"maxIdle": 3,
43-
"maxActive": 3,
41+
sess, err = Connect(ConnectOpts{
42+
Address: url,
43+
MaxIdle: 3,
44+
MaxActive: 3,
4445
})
4546
c.Assert(err, test.IsNil)
4647
}

query.go

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package gorethink
22

33
import (
4-
"code.google.com/p/goprotobuf/proto"
54
"fmt"
6-
p "github.com/dancannon/gorethink/ql2"
75
"strconv"
86
"strings"
7+
8+
"code.google.com/p/goprotobuf/proto"
9+
p "github.com/dancannon/gorethink/ql2"
910
)
1011

1112
type OptArgs interface {
@@ -15,6 +16,7 @@ type termsList []RqlTerm
1516
type termsObj map[string]RqlTerm
1617
type RqlTerm struct {
1718
name string
19+
rootTerm bool
1820
termType p.Term_TermType
1921
data interface{}
2022
args []RqlTerm
@@ -55,7 +57,45 @@ func (t RqlTerm) build() *p.Term {
5557
}
5658
}
5759

58-
// compose returns a string representation of the query tree
60+
func (t RqlTerm) compose(args []string, optArgs map[string]string) string {
61+
switch t.termType {
62+
case p.Term_MAKE_ARRAY:
63+
return fmt.Sprintf("[%s]", strings.Join(argsToStringSlice(t.args), ", "))
64+
case p.Term_MAKE_OBJ:
65+
return fmt.Sprintf("{%s}", strings.Join(optArgsToStringSlice(t.optArgs), ", "))
66+
case p.Term_FUNC:
67+
// Get string representation of each argument
68+
args := []string{}
69+
for _, v := range t.args[0].args {
70+
args = append(args, fmt.Sprintf("var_%d", v.data))
71+
}
72+
73+
return fmt.Sprintf("func(%s r.RqlTerm) r.RqlTerm { return %s }",
74+
strings.Join(args, ", "),
75+
t.args[1].String(),
76+
)
77+
case p.Term_VAR:
78+
return fmt.Sprintf("var_%s", t.args[0])
79+
case p.Term_IMPLICIT_VAR:
80+
return "r.Row"
81+
case p.Term_DATUM:
82+
switch v := t.data.(type) {
83+
case string:
84+
return strconv.Quote(v)
85+
default:
86+
return fmt.Sprintf("%v", v)
87+
}
88+
89+
default:
90+
if t.rootTerm {
91+
return fmt.Sprintf("r.%s(%s)", t.name, strings.Join(allArgsToStringSlice(t.args, t.optArgs), ", "))
92+
} else {
93+
return fmt.Sprintf("%s.%s(%s)", t.args[0].String(), t.name, strings.Join(allArgsToStringSlice(t.args[1:], t.optArgs), ", "))
94+
}
95+
}
96+
}
97+
98+
// String returns a string representation of the query tree
5999
func (t RqlTerm) String() string {
60100
switch t.termType {
61101
case p.Term_MAKE_ARRAY:
@@ -86,10 +126,10 @@ func (t RqlTerm) String() string {
86126
}
87127

88128
default:
89-
if t.name != "" {
129+
if t.rootTerm {
90130
return fmt.Sprintf("r.%s(%s)", t.name, strings.Join(allArgsToStringSlice(t.args, t.optArgs), ", "))
91131
} else {
92-
return fmt.Sprintf("(%s)", strings.Join(allArgsToStringSlice(t.args, t.optArgs), ", "))
132+
return fmt.Sprintf("%s.%s(%s)", t.args[0].String(), t.name, strings.Join(allArgsToStringSlice(t.args[1:], t.optArgs), ", "))
93133
}
94134
}
95135
}

0 commit comments

Comments
 (0)