1.1.6 • Published 5 years ago

couchdb-query-helper v1.1.6

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago