Skip to content

Commit ec15098

Browse files
authored
Merge pull request #104 from ptgamr/master
README for indexes creation & retrieval
2 parents 0ea4af3 + f48e6b9 commit ec15098

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ See [API documentation](http://hexdocs.pm/rethinkdb/) for more details.
1919

2020
###Connection
2121

22-
Connections are managed by a process. Start the process by calling `start_link/1`. See [documentation for `Connection.start_link/1`](http://hexdocs.pm/rethinkdb/RethinkDB.Connection.html#start_link/1) for supported options.
22+
Connections are managed by a process. Start the process by calling `start_link/1`. See [documentation for `Connection.start_link/1`](http://hexdocs.pm/rethinkdb/RethinkDB.Connection.html#start_link/1) for supported options.
2323

2424
####Basic Remote Connection
2525
```elixir
@@ -131,6 +131,33 @@ table("people")
131131

132132
See [query.ex](lib/rethinkdb/query.ex) for more basic queries. If you don't see something supported, please open an issue. We're moving fast and any guidance on desired features is helpful.
133133

134+
#### Indexes
135+
```elixir
136+
# Simple indexes
137+
# create
138+
result = Query.table("people")
139+
|> Query.index_create("first_name", Lambda.lambda fn(row) -> row["first_name"] end)
140+
|> RethinkDB.run conn
141+
142+
# retrieve
143+
result = Query.table("people")
144+
|> Query.get_all(["Will"], index: "first_name")
145+
|> RethinkDB.run conn
146+
147+
148+
# Compound indexes
149+
# create
150+
result = Query.table("people")
151+
|> Query.index_create("full_name", Lambda.lambda fn(row) -> [row["first_name"], row["last_name"]] end)
152+
|> RethinkDB.run conn
153+
154+
# retrieve
155+
result = Query.table("people")
156+
|> Query.get_all([["Will", "Smith"], ["James", "Bond"]], index: "full_name")
157+
|> RethinkDB.run conn
158+
```
159+
One limitation we have in Elixir is that we don't support varargs. So in JavaScript you would do `getAll(key1, key2, {index: "uniqueness"})`. In Elixir we have to do `get_all([key1, key2], index: "uniqueness")`. With a single key it becomes `get_all([key1], index: "uniqueness")` and when `key1` is `[partA, partB]` you have to do `get_all([[partA, partB]], index: "uniqueness")`
160+
134161
###Changes
135162

136163
Change feeds can be consumed either incrementally (by calling `RethinkDB.next/1`) or via the Enumerable Protocol.

0 commit comments

Comments
 (0)