Title: | RethinkDB Client |
---|---|
Description: | Simple, native 'RethinkDB' client. |
Authors: | Miron B. Kursa |
Maintainer: | Miron B. Kursa <[email protected]> |
License: | GPL-3 |
Version: | 1.1.0 |
Built: | 2024-12-22 06:23:21 UTC |
Source: | CRAN |
Closes connection and stops all associated callbacks and/or sync cursor.
## S3 method for class 'RethinkDB_connection' close(con, ...)
## S3 method for class 'RethinkDB_connection' close(con, ...)
con |
Connection to close. |
... |
Ignored. |
Closes a given cursor and stops its associated query. Should be called on the current cursor before a new sync query is invoked on the same connection.
## S3 method for class 'RethinkDB_cursor' close(con, ...)
## S3 method for class 'RethinkDB_cursor' close(con, ...)
con |
Cursor to close. |
... |
Ignored. |
Pulls a datum from a given cursor, sending continuation queries when needed.
cursorNext(cursor, inBatch = FALSE)
cursorNext(cursor, inBatch = FALSE)
cursor |
Cursor to pull from; a result of |
inBatch |
If set to |
In a default mode, a list representing the returned response JSON, or NULL
if no data is available.
In a batch mode, list of such lists representing the whole cache (which may be empty, corresponding to default mode's NULL
).
When this function empties local cache, it may ask RethinkDB for more data and hence block.
Use isCursorEmpty
to decide if it makes sense to call cursorNext
.
In case you don't need any more answers for the query, close cursor with close
method.
Miron B. Kursa
Converts cursor into a list.
For convenience, when given anything other than cursor returns this object unchanged; this way can be used to wrap the result of $run
, so that it is never a cursor.
cursorToList(x, maxResults = 10000)
cursorToList(x, maxResults = 10000)
x |
RethinkDB cursor or any object. |
maxResults |
Number of results sufficient to stop pulling from cursor. |
A list of elements pulled from x
if it is a cursor, x
otherwise.
The lenght of a list may be larger than maxResults
because RethinkDB transmits results in batches.
Miron B. Kursa
Drains a given RethinkDB connection, i.e. pull query responses and both call their associated callbacks (for async queries) and/or filling sync cursor local cache. Draining ends when all async queries end; the function blocks for the entire time this is happening.
drainConnection(x)
drainConnection(x)
x |
Connection to drain. |
The async query callback will only fire during drainConnection
or (opportunistically) cursorNext
; consequently this function must be run to guarantee that installed callbacks will have a chance to fire.
Check whether a given cursor is fully drained and will output no more datum. The function never blocks; also verifies that the underlying connection is useful.
isCursorEmpty(cursor)
isCursorEmpty(cursor)
cursor |
Cursor to check; a result of |
TRUE
if cursor has no more data to return.
It is possible that cursorNext
will return NULL
just after isCursorEmpty
returns FALSE
.
Changefeeds cursors (made with r()$...$changes()$...
) will never become empty (provided that connection won't become broken).
Miron B. Kursa
Check whether a given connection is opened. Closed connections cannot be used, and will throw errors on such an attempt; their associated callbacks and/or sync cursor are dead and won't fire/produce any more data.
isOpened(x)
isOpened(x)
x |
Connection to to check. |
TRUE
if connection is opened and can be used for queries, FALSE
otherwise.
Miron B. Kursa
Opens connection to a given RethinkDB server.
openConnection(host = "localhost", port = 28015, authKey = NULL, v = "V0_4")
openConnection(host = "localhost", port = 28015, authKey = NULL, v = "V0_4")
host |
Host to connect to. |
port |
Port to connect to. |
authKey |
Authentication key. Not supported yet. |
v |
Protocol version; |
Object of a class RethinkDB_connection
, which can be passed to r()$...$run
and r()$...$runAsync
functions.
Prints a RethinkDB connection details, including a number of pending callbacks.
## S3 method for class 'RethinkDB_connection' print(x, ...)
## S3 method for class 'RethinkDB_connection' print(x, ...)
x |
Connection to print. |
... |
Ignored. |
Never blocks.
Prints a given cursor's status.
## S3 method for class 'RethinkDB_cursor' print(x, ...)
## S3 method for class 'RethinkDB_cursor' print(x, ...)
x |
Cursor to print. |
... |
Ignored. |
Never blocks; also checks whether the underlying connection is alive.
Creates ReQL root for building a query.
r(db, table)
r(db, table)
db |
DB name; this is optional, and is just a syntax sugar for |
table |
Table name; this is optional, requires db to be given, and is just a syntax sugar for |
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 |
runAsync(connection , callback , ...)
|
Evaluate the query; for each datum received |
bracket(...) |
Implementation of the JavaScript |
funcall(function , atts)
|
Implementation of the JavaScript |
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
.
Miron B. Kursa
## 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)
## 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)