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

rethinkdb_adapter

v0.1.3

Published

Adapter/connector for RethinkDB with simple query/persistence interface

Downloads

5

Readme

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 = new db.Adapter({
  host: process.env.RDB_HOST || 'localhost',
  port: parseInt(process.env.RDB_PORT) || 28015,
  db: process.env.RDB_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.post('/posts', restrict, function (req, res) {
  db.createRecord('posts', req.body.posts, function (err, payload) {
    if (err) {
      logerror(err);
      res.status(500).end();
    } else {
      loginfo('payload', payload.posts);
      if (app._io) {
        loginfo('didAdd', payload);
        app._io.emit('didAdd', payload);
      }
      res.status(201).send(payload);
    }
  });
});

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.patch('/posts/:id', restrict, function (req, res) {
  db.patchRecord('posts', req.params.id, req.body, function (err) {
    if (err) {
      logerror(err);
      res.status(500).end();
    } else {
      res.status(204).end();
    }
  });
});

A PUT request to update an author

/**
  Update a author by id

  Route: (verb) PUT /authors/:id
  @async
**/
app.put('/authors/:id', restrict, function (req, res) {
  db.updateRecord('authors', req.params.id, req.body.authors, function (err) {
    if (err) {
      logerror(err);
      res.status(500).end();
    } else {
      res.status(204).end();
    }
  });
});

Links