RethinkDB

Component ID

2760069

Component name

RethinkDB

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

194

Component created

Component changed

Component body

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
    below:
<?php

$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
things:

  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:

Creating

$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

Loading the entity is very easy:

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

Or

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

You can get the values of the document:

$document->get('title');
$document->get('body');
$document->getValues();

Updating

Don’t worry. It’s very easy:

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

Deleting

As before, it’s EASY:

$document->delete();
Query

Basic query

Let’s warm up with some nice query:

    $messages = Drupal::entityQuery('rethinkdb_message')
      ->execute();

condition

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

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

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

Contribution

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