npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

couchbase-server-promises

v4.0.2

Published

An A+ Promises wrapper for the Couchbase SDK with added support for manage documents stored in your Couchbase database directly by their document identifiers

Downloads

64

Readme

couchbase-server-promises

A promise-based asynchronous library for Couchbase and node.js.

The Official Couchbase Node.js Client Library provides only callback functions to handle the result of the asynchronous operations. This couchbase-server-promises library wraps those callback functions with Bluebird promises to provide a convenient, promise-based interface.

Usage

First, install couchbase-server-promises as a dependency:

npm install --save couchbase-server-promises

In order to init it, you should use a config. The config should have a structure like this:

const config = {
  cluster: [ 'couchbase://127.0.0.1:8091' ],
  buckets: [
    {
      bucket: 'customers',
    },
    {
      bucket: 'stats',
    }, 
    {
      bucket: 'users'
    }
  ],
  user: 'testUser',
  password: 'testPassword',
};

as buckets we add all couchbase's bucket(name&password(password is not required)), that we have in our cluster. Also you can specify multiple hosts(clusters) in the connection string(cluster's array in config). To specify multiple hosts, separate them using a comma, for example: cluster: [couchbase://127.0.0.1:8091,couchbase://127.0.0.1:8092]. Also, you can specify operationTimeout for each bucket(not required).

Then, reference it in your code file:

const couchbasePromisesWrapper = require('couchbase-server-promises')(config);

Use the methods of the couchbasePromisesWrapper class to manage documents stored in your Couchbase database directly by their document identifiers:

Exported Methods:

  • getDoc(bucket, docId)
  • upsertDoc(bucket, docId, newDoc)
  • insertDoc(bucket, docId, newDoc)
  • replaceDoc(bucket, docId, newDoc)
  • removeDoc(bucket, docId)
  • getMultiDocs(bucket, [ docIds ])
  • query(bucket, query)
  • getBucketManager(bucket): Returns bucket.manager
  • getConnectedBuckets(): Returns array of connected buckets
  • disconnectBucket(bucket): Disconnects from bucket

where: bucket: is the name of bucket we want to manage doc, docId: is the doc's name we want to manage, newDoc: is the doc's struct that we want to store in docId

Example

  1. Get doc with name user:test from customers bucket:
try {
  const doc = await couchbasePromisesWrapper.getDoc('customers', 'user:test');
  /*code*/
} catch(error) {
  /*code*/
}
  1. Get doc with name statistics:test from stats bucket:
try {
  const doc = await couchbasePromisesWrapper.getDoc('stats', 'statistics:test');
  /*code*/
} catch(error) {
  /*code*/
}
  1. Update doc with name statistics:test from stats bucket with a new object called newTestValue:
try {
  const doc = await couchbasePromisesWrapper.upsertDoc('stats', 'statistics:test', newTestValue)
  /*code*/
} catch(error) {
  /*code*/
};
  1. Remove doc with name statistics:test from stats bucket:
try {
  const doc = await couchbasePromisesWrapper.removeDoc('stats', 'statistics:test')
  /*code*/
} catch(error) {
  /*code*/
};
  1. Replace doc with name statistics:test from stats bucket with a new object called newTestValue:
try {
  const doc = await couchbasePromisesWrapper.replaceDoc('stats', 'statistics:test', newTestValue)
  /*code*/
} catch(error) {
  /*code*/
};
  1. Add new doc with name statistics:test in stats bucket with value: newTestValue:
try {
  const doc = await couchbasePromisesWrapper.insertDoc('stats', 'statistics:test', newTestValue)
  /*code*/
} catch(error) {
  /*code*/
};
  1. Get list of docs(multi) with name statistics:test1, statistics:test2 and statistics:test3:
try {
  const docs = await couchbasePromisesWrapper.getMultiDocs('stats', [
    'statistics:test1',
    'statistics:test2',
    'statistics:test3',
  ])
  /*code*/
} catch(error) {
  /*code*/
};
  1. Make query to stats bucket using a view:
const view = couchbasePromisesWrapper.ViewQuery
  .from('testView', 'test')
  .range(startkey, endkey)
  .order(order)
  .reduce(false)
  .limit(24)
  .skip(10);
  
couchbasePromisesWrapper.query('stats', view)
.then(doc => {
  /*code*/
})
.catch(error => {
  /*code*/
});
  1. Make query to stats bucket using a N1qlQuery:
const sqlQuery = couchbasePromisesWrapper.N1qlQuery.fromString(`
  SELECT * FROM \`stats\`
  WHERE type = "test";
`);
  
couchbasePromisesWrapper.query('stats', sqlQuery)
.then(doc => {
  /*code*/
})
.catch(error => {
  /*code*/
});