Unfortunately this driver is no longer maintained, and we'd recommend to use https://github.com/hamiltop/exrethinkdb
The reasons for this:
- It was written for
Elixir 0.10.2
using the Records system that has become obsolete in the final version1.0
of the language; - To support the communication was used Google Protocol Buffer through the library https://github.com/azukiapp/elixir-protobuf, which also is deprecated;
- The latest version of Rethinkdb makes use of JSON in communication;
- The Azuki is primarily involved with http://azk.io project, so a little time has left over for our work with Elixir. : /
This is a prototype of a RethinkDB client driver written in Elixir. This driver utilizes Erlang R16B01 and Elixir 0.10.1.
Current version was tested: RethinkDB 1.8.1
Add the following to your list of dependencies in mix.exs:
{ :rethinkdb, github: "azukiapp/elixir-rethinkdb" }
defmodule Simple.Marvel do
use Rethinkdb
def get(name) do
r.table("marvel").get(name).run!
end
end
defmodule Simple.App do
use Rethinkdb
def start do
r.connect("rethinkdb://localhost:28015/test").repl
end
end
Open connection and create a table:
iex> Rethinkdb.start
iex> use Rethinkdb
iex> conn = rr.connect(db: test)
iex> rr.table_create("marvel", primary_key: "name").run(conn)
{:ok, #HashDict<[created: 1.0]>}
Insert a document
iex> batman = [name: "batman", rich: true, cars: [1, 2, 3]]
iex> rr.table("marvel").insert(batman).run!(conn)
#HashDict<[deleted: 0.0, errors: 0.0, inserted: 1.0, replaced: 0.0,
skipped: 0.0, unchanged: 0.0]>
Making life easier:
iex> conn.repl # now this connection is default
iex> table = rr.table("marvel")
Update document:
iex> table.get("batman").update(age: 30).run!
iex> table.get("batman").run!
#HashDict<[age: 30.0, cars: [1.0, 2.0, 3.0], name: "batman", rich: true]>
iex> table[0]["name"].run!
"batman"
Map a document with function:
iex> table.map(fn hero ->
hero[:name].add(" ").add(hero[:age].coerce_to("string"))
end).run!
["batman 30"]
iex> table.map(rr.row[:age].add(10)).run!
[40.0]
The Elixir driver is most similar to the official Python driver. Most of the functions have the same names as in the python driver.
- Due to a compatibility problem with the function of
r
iex, to runuse
Rethinkdb in iex,rr
method is imported in place of the methodr
as is usual.
"Azuki" and the Azuki logo are copyright (c) 2013 Azuki Serviços de Internet LTDA..
Exdocker source code is released under Apache 2 License.
Check LEGAL and LICENSE files for more information.