New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

rethink-odm

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rethink-odm

Simple Object Document Mapper for RethinkDB.

latest
Source
npmnpm
Version
0.1.2
Version published
Weekly downloads
8
300%
Maintainers
1
Weekly downloads
 
Created
Source

rethink-odm

Build Status Dependency Status devDependency Status

Simple Object Document Mapper for RethinkDB.

Install

npm install rethink-odm

Usage

var ro = require('rethink-odm')();

// Run command without waiting connection to be ready.
ro.run(ro.r.now()).then(function (now) {
  // ...
});

// Create the model "User".
var User = ro.createModel({
  tableName: 'users'
});

// Create a new User.
var user = new User({
  name: 'Johnny'
});

// Create model.
user.create().then(function (user) {
  // ...
});

rethinkOdm(options) / rethinkOdm.createClient(options)

Create a new rethinkOdm client. To know avalaible options, please refer to rethinkdb documentation.

var ro = rethinkOdm({host: 'localhost'});

Events

error

Emitted when an error occurs in the connection.

ro.on('error', function (err) {});
connect

Emitted when the client is connected.

ro.on('connect', function () {});
close

Emmited when the connection is closed.

ro.on('close', function () {});

ro.r

Expose the rethinkdb module.

ro.r.now();

ro.run(command, [cb])

Run a command using the internal rethink odm connection. The advantage is that you don't have to wait connection to be ready.

ro.run(ro.r.now()).then(function (now) {
  // ... 
});

ro.createModel(options)

Create a new model.

  • tableName: Name of the table
  • hooks: Hooks
var User = ro.createModel({tableName: 'users'});

Hooks

It's possible to add some hooks, hook are some listeners automatically applied at initialization.

var User = ro.createModel({
  tableName: 'users',
  hooks: {
    insert: function () {
      if (! this.email) throw new Error('Email is required');
    }
  }
});

Model.table()

Return the table linked to the model.

ro.run(User.table().get('1a487dc0-f6ec-11e3-a3ac-0800200c9a66'));

new Model([data])

Create a new instance of the model.

var user = new User({name: 'Johnny'});

model.insert([cb])

Insert the model.

var user = new User({name: 'Johnny'});
user.insert().then(function (user) {
  // ...
});

Events

insert

Emitted before the insert.

model.on('insert', function (model) {});
inserted

Emitted after the insert.

model.on('inserted', function (model) {});

model.update([data], [cb])

Update the model.

var user = new User({
  id: '1a487dc0-f6ec-11e3-a3ac-0800200c9a66',
  name: 'Johnny'
});
user.update().then(function (user) {
  // ...
});

Events

update

Emitted before the update.

model.on('update', function (model, data) {});
updated

Emitted after the update.

model.on('updated', function (model, data) {});

model.delete([cb])

Delete the model.

var user = new User({id: '1a487dc0-f6ec-11e3-a3ac-0800200c9a66'});
user.delete().then(function () {
  // ...
});

Events

delete

Emitted before the deletion.

model.on('delete', function (model) {});
deleted

Emitted after the deletion.

model.on('deleted', function (model) {});

License

MIT

Keywords

rethinkdb

FAQs

Package last updated on 01 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts