RethinkDB Adapter
Adapter/connector for RethinkDB with simple query/persistence interface
See the adapter.js file which represents the interface for connecting, querying, performing CRUD operations, and includes methods:
- find
- findMany
- findQuery
- createRecord
- updateRecord
- deleteRecord
- patchRecord
- findBySlug
- updateRecordBySlug
- deleteRecordBySlug
- uuid
- setup
The above method names may look familiar if you've used the Ember.js client-side framework together with a data persistence library such as Ember Data, or Orbit.js.
This module was developed for a simple API for a blog application without a model layer, simply adapting a request to a resource in the database. The adapter provides a simple interface to persist JSON data from a (smart) client application that has a model layer, it's own validations, and relelationship management; such as using the JSON API spec or JSON Patch.
Install
npm install rethinkdb_adapter --save
Connect
Require the module
var db = require('rethinkdb_adapter');
Environment variables used to connect to your database:
- RDB_HOST
- RDB_PORT
- RDB_DB
Below is the default connection setup
/** RethinkDB database settings. Defaults can be overridden using environment variables. @method find**/var adapter = host: processenvRDB_HOST || 'localhost' port: || 28015 db: processenvRDB_DB;
Examples
Below are a few examples taken from a simple blog API using Node.js w/ Express
Refer to: https://github.com/pixelhandler/blog/tree/master/server
Create a record, e.g. a blog post
/** Create a post Route: (verb) POST /posts @async**/app;
A JSON Patch request to update a blog post title:
/** Patch a post by id, supports replace and remove operations Route: (verb) PATCH /posts/:id Example payload: [{ "op": "replace", "path": "/title", "value": "Refreshed my Blog with Express and Ember.js" }] @async**/app;
A PUT request to update an author
/** Update a author by id Route: (verb) PUT /authors/:id @async**/app;