npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rethink-odm

v0.1.2

Published

Simple Object Document Mapper for RethinkDB.

Downloads

7

Readme

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