Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remodel

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remodel

Generator-based query interface for rethinkdb.

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Remodel

Generator-based query interface for rethinkdb.

A simple wrapper around the excellent rethinkdb lib, with generator support, and some modeling goodness thrown in.

Installation

$ npm install remodel

Example

var r = require('rethinkdb');
var co = require('co');

var remodel = require('./')('localhost');

var User = remodel.create('Users');

co(function *() {
  var dbList = yield remodel(r.dbList());
  var user = yield User.filter({email: 'a@test.com'});
})();

Usage

var r = require('rethinkdb');

// Provide connection details when requiring remodel.
// These connection details are passed directly to reql-then
// which sets up a connection pool for you
remodel = require('remodel'){
  host: 'localhost',
  port: 28015,
  db: 'test',
  authKey: '',
  maxPoolSize: 10 // set to 1 to disable connection pooling
});

// query interface
function *() {
  // accepts any rethinkdb query
  yield remodel.query(r.dbList());
  yield remodel.query(r.db('test').tableList());
  yield remodel.query(r.db('test').table('Users').insert({email: 'test@test.com'}));

  // aliases
  yield remodel.q(r.dbList());
  yield remodel(r.dbList());
}

// model interface
var User = remodel.create('Users'); // pass the table name
function *() {
  yield User.all(); // returns all users

  // add your own helper finder methods
  User.findByEmail = function *(email) {
    return yield this.filter({email: email.trim().toLowerCase()});
  }

  // use regular rethinkdb querying
  var user = yield User.get(1234); // primary key lookup
  var users = yield User.filter({email: 'test@test.com'});
  var users = yield User.getAll('test@test.com', {index: 'email'}); // use an index for faster querying

  // complete list
  yield User.between
  yield User.count
  yield User.filter
  yield User.forEach
  yield User.get
  yield User.getAll
  yield User.groupBy
  yield User.groupedMapReduce
  yield User.indexCreate
  yield User.indexList
  yield User.indexWait
  yield User.info
  yield User.insert
  yield User.limit
  yield User.map
  yield User.orderBy
  yield User.pluck
  yield User.skip
  yield User.union
  yield User.withFields
  yield User.without
}

License

MIT

Keywords

FAQs

Package last updated on 15 Jan 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc