r: ReQL root

Description Usage Arguments Value Note Author(s) Examples

View source: R/reql.R

Description

Creates ReQL root for building a query.

Usage

1
r(db, table)

Arguments

db

DB name; this is optional, and is just a syntax sugar for r()$db(db).

table

Table name; this is optional, requires db to be given, and is just a syntax sugar for r()$db(db)$table(table)

Value

ReQL root; use $ (or [[]]) to chain query terms (like r()$db("test")$table("test")). In general, anonymous attributes are passed as attributes while named as term options. In context of term arguments, named lists are treated as JSON objects (following rjson package heuristics), unnamed lists and simple vectors as JSON arrays; classes and attributes are ignored. Term options should be called in the snake case form (for instance return_changes not returnChanges), as documented for the original Python driver. To finalise, use $run or $runAsync. For a comprehensive description of all terms, see RethinkDB API reference; here we give an overview of some:

run(connection,...)

Evaluate the query; the function will block until first response from RethinkDB to this query will be received. May return cursor, an object representing a stream of data on which cursorNext and cursorToList can be used to extract actual information. ... may be used to specify run options, like profile, durability or read_mode.

runAsync(connection,callback,...)

Evaluate the query; for each datum received x, run callback(x). Callback should return TRUE to be re-evaluated on proceeding data; any other response will cause the query to be dropped immediately. This function returns immediately; to ask R to start evaluating async queries, run drainConnection. Note that callbacks can be also called while $run() blocks waiting for other query to execute.

bracket(...)

Implementation of the JavaScript (...) and Python [...] operation.

funcall(function,atts)

Implementation of the JavaScript .do(); note that the order of arguments is different.

Note

ReQL is implemented as an environment, thus is mutable unlike most R objects. To this end, you can use variables for chaining like this r()->query; query$db("a"); query$table("b"); but consequently you can't use variables to make a re-usable stub, i.e., this is invalid: r()->query; query$db("a")$table("aa")$run(...) query$db("b")$table("bb")$run(...);.

If you get "trying to apply non-function" error, you likely have misspelled term name or trying to use a non-existent one.

To view raw AST (at any depth), use $query.

Author(s)

Miron B. Kursa

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
## Not run: 
#Connect to the RethinkDB instance
cn<-openConnection()

#Get document count in some_db's some_table
r()$db("some_db")$table("some_table")$count()$run(cn)
#...same can be done shorter
r("some_db","some_table")$count()$run(cn)

#Fetch 5 random docs from some_db's some_table...
r("some_db","some_table")$sample(5)$run(cn)->cursor
#...and present as a list`
cursorToList(cursor)

#Insert an element
r("some_db","some_table")$insert(list(id="new",a=1:10,b=list(c=1,d=2)))$run(cn)

#Close connection
close(cn)

## End(Not run)

mbq/rethinker documentation built on May 22, 2019, 12:57 p.m.