rethink-crud

1.0.7 • Public • Published

RethinkDB crud helper methods for NodeJS

Prerequisites

  1. Install rethink db

    https://rethinkdb.com/docs/install/

  2. Start rethinkdb by running

rethinkdb

Steps to create a database and a collection to get started

const rethinkDb = require("rethink-crud");


// Connect the wrapper engine with rethinkdb
await rethinkDb.startEngine({
  host: "localhost",
  port: 28015,
});

// Create a db to start
await rethinkDb.createDb("my-db");

// Db created!
// So get the db reference to use it further
const db = new rethinkDb("my-db");

// Create a collection (table) on the db
await db.createCollection("notes");

// Show all collections
const collections = await db.listCollections();
console.log("collections :>> ", collections);

Easy CRUD operations

const rethinkDb = require("rethink-crud");


// Connect the wrapper engine with rethinkdb
await rethinkDb.startEngine({
  host: "localhost",
  port: 28015,
});

// Initiate the wrapper 
// and pass the database name currently you want to work with 
// So it will be selected by default for future operations
// It will return the database reference
const db = new rethinkDb("my-db");

// Now get the collection reference you want to work with
const notes = db.collection("notes");

// Add a document
await notes.add({myNoteText: "Rethinkdb is a realtime no sql database!", author: "Debojyoti"});

// Get all documents
const allNotes = await notes.get();

// Get filtered doc(s)
const debojyotiNotes = await notes.get({author: "Debojyoti"});

// Update a specific doc
await notes.update(
  {author: "Debojyoti"},                           //  Here goes the filters
  {email: "debojyoti.js@gmail.com"}                // And now what to update
);

// Delete a specific doc
await notes.delete(
  {author: "Debojyoti"}                           //  Here goes the filters
);

Readme

Keywords

Package Sidebar

Install

npm i rethink-crud

Weekly Downloads

2

Version

1.0.7

License

ISC

Unpacked Size

10.5 kB

Total Files

4

Last publish

Collaborators

  • debojyoti