1.0.7 • Published 4 years ago

rethink-crud v1.0.7

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

RethinkDB crud helper methods for NodeJS

npm.io

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
);
1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago