Skip to content

rajcrk/couchdb-query-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

couchdb-query-helper

npm version A module to help query couch DB in node applications

couchdb-query-helper is a library that can help you build query, schema, and control your database more easier.

Presently can only be used on the NodeJS version 8 or higher.Supports CouchDb version 15.10 or higher.

Installation

npm i couchdb-query-helper

How to use

Initializing the library

couchdb-query-helper module is itself a function which takes a configuration object.

const queryHelper = require('couchdb-query-helper')
  .connection({
    host: 'localhost',
    protocol: 'http://',
    port: '5984',
    user: 'admin',
    pass: 'admin'
  });

Retrieving results

Retrieving All Rows From A Table

queryHelper
    .query()
    .selectAll(tableName)
    .then((responseData) => console.log(responseData))
    .catch((err) => console.log(err));

Retrieving All Databases available

queryHelper
    .db()
    .showDatabases()
    .then((responseData) => console.log(responseData))
    .catch((err) => console.log(err));

Inserting a document

queryHelper
    .query()
    .insert(documentId, documentData, databaseName)
    .then((responseData) => console.log(responseData)) 
    .catch((err) => console.log(err));

Deleting a document

queryHelper
    .query()
    .delete(documentId, databaseName)
    .then((responseData) => console.log(responseData)) 
    .catch((err) => console.log(err));

Select with condition (In Developement)

array_of_key represents the key that you are searching for and array_of_values represents the values that the key should have.

 queryHelper
    .query()
    .select(array_of_key, array_of_values, databaseName)
    .then((responseData) => console.log(responseData)) 
    .catch((err) => console.log(err));

Creating a new database

    queryHelper
        .db()
        .createDatabase(dbName)
        .then((responseData) => console.log(responseData)) 
        .catch((err) => console.log(err));

Drop a database

    queryHelper
        .db()
        .dropDatabase(dbName)
        .then((responseData) => console.log(responseData)) 
        .catch((err) => console.log(err));

Run your regular find with custom queries

You can use the regular JSON object for queries, to know more about the select option visit http://docs.couchdb.org/en/stable/api/database/find.html

    queryHelper
        .query()
        .bareSelect(dbName, selectorSample)
        .then((responseData) => console.log(responseData)) 
        .catch((err) => console.log(err));

About

A module to help query couch DB in node applications

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published