This is an ORM for RethinkDB. The module does not intend to replace the default DB drivers but to create entity representation in your RethinkDB of your Drupal installation entities.
- install RethinkDB
- Enable the module.
- Update Drupal autoloader using composer manager.
- Go to
admin/config/rethinkdb/rethinkdbconfig
and make sure your connection setting are good to go.
In order to define an entity based on RethinkDB storage you need to apply two things:
- The entity storage should be defined to
Drupal\rethinkdb\RethinkStorage
. - 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,
* handlers = {
* "storage" = "Drupal\rethinkdb\RethinkStorage"
* },
* entity_keys = {}
* )
*/
class RethinkMessages extends AbstractRethinkDbEntity {
}
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']));
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();
Don't worry. It's very easy:
$document->set('title', 'new title')->save();
As before, it's EASY:
$document->delete();
Let's warm up with some nice query:
$messages = \Drupal::entityQuery('rethinkdb_message')
->execute();
You can apply all the operations you know: =, !=, >, >=, <, <=, CONTAINS
:
$messages = \Drupal::entityQuery('rethinkdb_message')
->condition('title', 'fo', 'CONTAINS')
->execute();
Any PR is more than welcome. When creating the PR please ping me so I could know a contribution has been done. 10x.