Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

couchdbjs

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

couchdbjs

A node client for couchdb.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

couchdbjs

couchdbjs is node.js client for couchdb.

Install

$ npm install couchdbjs --save

Create a couchdbjs object

const Couchdbjs = require('couchdbjs');
const db = new Couchdbjs(dbname, options);

Note : Here DB is the object of the class couchdbjs.

Here options is an optional js object containing the configuration. This is the default configuration.

{
    protocol : 'http:',
    hostname: 'localhost',
    port: 5984
}

dbname is the name of the database.

Generate a new uuid

Couchdbjs.getNewId(options, cb);

Here options is optional configuration object. This is the default configuration.

{
    protocol : 'http:',
    hostname : 'localhost',
    port: 5984
    count : 1
}

cb is reqired callback function with two parameters err and data. To avoid writing configurations for protocol, hostname, etc. again the function getConfig can be called on existing database object.

db.getConfig({count : 1});

returns

{
    protocol : 'http:',
    hostname : 'localhost',
    port: 5984
    count : 1
}

Complete Example :

Couchdbjs.getNewId(db.getConfig({count : 1}, function(err, data) {
    if (err) console.error(err);
    else console.log(data[0]); // data is array of uuids
}));

Create a new database

const db = new Couchdbjs('dbname', options);

This creates a database when a database with name dbname doesn't exist. Database can also be created using Couchdbjs.createDB function.

Couchdbjs.createDB({
    protocol: 'http:',
    hostname: 'localhost',
    port: 5984,
    db: 'dbanme'
}, function(err, data)=>{
    if (err) console.error(err);
    else console.log(data);
});

Delete a database

Database can be deleted using function Couchdbjs.deleteDB similar to Couchdbjs.createDB.

Couchdbjs.deleteDB({
    protocol: 'http:',
    hostname: 'localhost',
    port: 5984,
    db: 'dbanme'
}, function(err, data) {
    if (err) console.error(err);
    else console.log(data);
});

List all documents in a database

db.getAllDocs(function(err, data) {
    if (err) console.error(err);
    else console.log(data);
});

Create a new document

db.createDoc(id, document, cb);

id is the id of the document to be used. document is the object to be stored in the document. cb is the callback function with parameters err and data. Example

db.createDoc('id_doc', {a:1, b:2, c:[5, 'k']}, function(err, data) {
    if (err) console.error(err);
    else console.log(data);
});

Get document

db.deleteDoc(id, cb);

id is the id of the document. cb is the callback function with parameters err and data. Example

db.getDoc('id_doc', function(err, data) {
    if (err) console.error(err);
    else console.log(data);
});

Keywords

FAQs

Package last updated on 19 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc