NoBrainer gives you a lot of sugar so you do not have to write RQL queries yourself. But to really leverage the power of RethinkDB, it is sometimes necessary to go down to the RQL interface. This section describes how to mix RQL statements with NoBrainer.
NoBrainer exposes a
run method to run arbitrary RQL command through the
query runner middlewares.
The following shows an example of the usage of
NoBrainer.run can either take the RQL query as an argument or as a
block. When passing a block, you get the
RQL shortcut passed in.
NoBrainer.run also accepts options to be passed in the RQL
Because running queries with certain options is useful (profiling, durability,
etc.), NoBrainer provides a method
NoBrainer.run_with() which specifies what options
to run the RQL queries with. For example:
NoBrainer.run_with() can be nested, and is thread safe.
You may use
run_with() to change database as described in the Multi
Generating RQL from NoBrainer
You can access the RQL table of a model with
User.rql_table. Such method
would return by default
r.table('users'), but can be overriden by the
store_in method described in the multi tenancy section.
When using a criteria, you may use
criteria.to_rql to retrieve the RQL query
that would be performed. For example:
When running raw RQL queries, you may get documents back in an attribute hash
format. You may use
Model.new_from_db(attrs) to instantiate a model with
attributes coming from the database. When using polymorphism, any class in
the hierarchy will do.