This project is not covered by Drupal’s security advisory policy.
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
- install RethinkDB
- 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:
- Add the
rethink = TRUE
settings in the annotatoin. - 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: =, !=, >, >=, <, <=, 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.
Project information
- Seeking new maintainer
The current maintainers are looking for new people to take ownership. - Module categories: Developer Tools, Integrations
- Created by RoySegall on , updated
- This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.