christopherhesse/rethinkgo

Support RethinkDB 1.5

Closed this issue · 6 comments

Particularly, to update the proto and allow creation/listing/usage of secondary indexes.

Secondary indexes are a huge win, and it'd be great to use them from within Go.

Thanks!

Yep, already got a note to myself to do this over the weekend. Thanks for the issue though!

Here's the list of changes:

We've defined variadic versions of table_create, table_drop, and table_list as toplevel functions that use the default database. So in e.g. the ruby driver users can write r.table_create('foo') to create a table foo in the default database (test unless the user sets it). These correspond to sending the TABLE_CREATE, TABLE_DROP, or TABLE_LIST protobuf terms to the server without their first argument.
The JAVASCRIPT protobuf term now takes an optional argument "timeout" which tells the server how long to wait before aborting the job (the default is 5 seconds).
There is a new protobuf term INFO which takes any value and gives an object containing information about it.
The endpoints of BETWEEN are now specified with positional arguments instead of optional arguments, with NULL used to denote an unbounded endpoint. So instead of setting left_bound to x and right_bound to y in the optional arguments, the first positional argument should be x and the second should be y. Or if there is no left bound, the first positional argument should be NULL and the second should be y.
We've added support for secondary indexes:
New terms SINDEX_CREATE, SINDEX_DROP, and SINDEX_LIST which do what you expect.
SINDEX_CREATE takes a table, a name for the index, and and an optional function. If you don't specify the function, the name of the index is assumed to be the name of a field in your rows, and the secondary index is created on that field. If you do specify a function, the secondary index is the value of that function when called on the field. So in Ruby, for example, r.table('test').sindex_create('first_name') would index the rows of test by the field first_name, while r.table('test').sindex_create('full_name') {|row| [row[:first_name], row[:last_name]]} would index the rows of test by both first and last name.
SINDEX_DROP takes a table and the name of an index to drop.
SINDEX_LIST takes a table and lists all of the secondary indexes for that table (analagous to TABLE_LIST).
There is a new term GET_ALL which takes a table, a value and an optional argument "index", then gets all rows from that table where the specified index has the specified value. If no index is specified it defaults to using the primary key.
BETWEEN and EQ_JOIN now take an optional argument "index" which makes them operate on a secondary index rather than the primary key.
You can see what all of these changes look like in the protobuf, too: https://github.com/rethinkdb/rethinkdb/blob/next/src/rdb_protocol/ql2.proto.

Cool! :) Yeah, I checked out the proto just to see if it was feasible for me to do it if I had to.

Excited to play with this. Thanks!

Put it in master:

b442d69

LGTM. Works fine over here, working with secondary indexes right now. Thanks for the quick turnaround!