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

couchdb-client

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

couchdb-client

A simple couchdb client

  • 1.0.11
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

CouchDBClient NPM version Build Status Dependency Status

Table of Contents

Example

welcome.js

var CouchDBClient = require('couchdb-client');
var client = new CouchDBClient({
    host: '127.0.0.1', //The host to connect to
    port: '5984' //The port
});
client.welcome(function (err, data) {
    console.log(err || data); //Hope it is not an error!
});

If all goes to plan we have a welcome message.

Usage

After requiring it, you will get a constructor. Call the constructor with options to get a client.

Documentation

This will be moved to another site eventually.

CouchDBClient([options])

This constructs your client. The options object can have: host: the host to connect to. Default: 127.0.0.1 port: the port to connect to. Default: 5984

var CouchDBClient = require('couchdb-client');
var client = new CouchDBClient({
    host: example.com,
    port: 3000
});

#welcome(callback)

Fetches the welcome message from the couchdb server.

client.welcome(function (err, data) {
    if (err) {
        console.error(err);
    } else {
        console.log(data);
    }
});

#getUUIDs(num, callback)

Gets UUIDs from the server.

var id;
client.getUUIDS(1, function (err, data) {
    if (err){
        console.error(err);
    } else {
        id = data;
    }
});

#createDB(name, callback)

Creates a database in the couchdb server. Will give an error if the database already exists.

client.createDB('foo', function (err, data) {
    if(err) {
        console.error(err);
    } else {
        console.log('Success:', data);
    }
});

#getDB(name, callback)

Get a database from the server.

var rev;
client.getDB('foo', function (err, data) {
    if (err) {
        console.error(err);
    } else {
        rev = data.rev;
        console.log(data);
    }
});

#deleteDB(name, callback)

Deletes a database.

client.deleteDB('foo', rev, function (err, data) {
    if (err) {
        console.error(err);
    } else {
        console.log(data);
    }
});

#addDoc(name, id, [rev], callback)

Adds a doc, could also be used to update a doc.

var rev2;
client.addDoc('foo', 'bar', {hi: true, bye false}, function (err, data) {
    if (err) {
        console.error(err);
    } else {
        rev2 = data.rev;
        console.log(data);
    }
});

#getDoc(name, id, callback)

Gets a document from the database.

client.getDoc('foo', 'bar', function (err, data) {
    if (err) {
        console.error(err);
    } else {
        console.log(data);
    }
});

#deleteDoc(name, id, rev, callback)

Deletes a document.

client.deleteDoc('foo', 'bar', rev, function (err, data) {
    if (err) {
        console.error(err);
    } else {
        console.log(data);
    }
});

#addView(name, id, obj, callback)

Adds or updates a view.

client.addView('test', 'stuff', {all: {map: "function (doc){emit(null,doc)}"}}, function (err, data) {
    if (err) {
        console.error(err);
    } else {
        rev = data.rev;
        console.log(data);
    }
});

#deleteView(name, id, rev, callback)

Deletes a view.

client.deleteView('test', 'stuff', rev, function (err, data) {
    if (err) {
        console.error(err);
    } else {
        console.log(data);
    }
});

#useView(name, id, view, [key,] callback)

Uses a view with the specified key.

client.useView('test', 'stuff', 'all', 'hi', function (err, data) {
    if (err) {
        console.error(err);
    } else {
        console.log(data);
    }
});

Test

$  npm test

Lisence

MIT

Keywords

FAQs

Package last updated on 12 Jun 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