This project is not covered by Drupal’s security advisory policy.

RethinkDB for Drupal

The work contribution done in Github

This is an ORM for RethinkDB. Which mean the module does not intend to replace
the default DB drivers but to create entity representation of your RethinkDB in
your Drupal installation.

Setting up

  1. install RethinkDB
  2. In the settings.php file add the RethinkDB connection credentials as listed

$settings['rethinkdb'] = array(
 'database' => 'drupal8',
 'host' => 'localhost',

Writing you custom entity

In order to define an entity based on RethinkDB storage you need to apply two

  1. Add the rethink = TRUE settings in the annotatoin.
  2. The entity class need to extends from AbstractRethinkDbEntity

You can have a look in the next example or in RethinkDB example module:

 * @ContentEntityType(
 *   id = "rethinkdb_message",
 *   label = @Translation("RethinkDB messages"),
 *   base_table = "rethinkdb_messages",
 *   translatable = FALSE,
 *   rethink = TRUE,
 *   entity_keys = {}
 * )
class RethinkMessages extends AbstractRethinkDbEntity {

CRUD operations

The CRUD operations are not different from the Drupal’s entity API:


$message = RethinkMessages::create(['title' => 'Foo', 'body' => 'Bar']);
$results = $message->save();

The returned value is an array with some information from RethinkDB on the
creation operation. You are probably interested with the ID of the entity you
just created. Unlike schematic DBs, RethinkDB is a NoSQL server which mean the
ID’s of the rows, or documents, is a simple hash.


Loading the entity is very easy:

$document = RethinkMessages::load(reset($results['generated_keys']));


$document = RethinkMessages::load('404bef53-4b2c-433f-9184-bc3f7bda4a15');

You can get the values of the document:



Don’t worry. It’s very easy:

$document->set('title', 'new title')->save();


As before, it’s EASY:


Basic query

Let’s warm up with some nice query:

    $messages = \Drupal::entityQuery('rethinkdb_message')


You can apply all the operations you know: =, !=, &gt;, &gt;=, &lt;, &lt;=, CONTAINS:

    $messages = \Drupal::entityQuery('rethinkdb_message')
      ->condition('title', 'fo', 'CONTAINS')

When executing the query, the query will return the objects and not the IDs of
the matching documents.


Any PR is more than welcome. When creating the PR please ping me so I could know
a contribution has been done. 10x.

Project information