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

@ossdeveloper/couchpromise

v1.6.1

Published

Couchbase SDK for node.js - with promises

Downloads

8

Readme

@ossdeveloper/couchpromise - As Promised : Under active development

couchbase SDK for Node.js - with promises

Prerequisites

  1. Ensure node-gyp is installed globally(npm install -g node-gyp)
  2. node.js version >= 10.13.0

Installation

  • npm install --save @ossdeveloper/couchpromise

Above command installs couchbase and 'q' promise library as dependencies.

Assumptions

  1. Your couchbase cluster username is 'username' and password is 'password'
  2. You have a bucket named 'default' in your couchbase cluster

List of operations - as promised

** You can use this library like regular couchbase node.js sdk and, use below methods for promises **

  1. Settingup buckets(DB connection) : setupBuckets
  2. insert : insertSingle
  3. upsert : upsertSingle
  4. replace : replaceSingle
  5. remove : removeSingle
  6. get : getSingle
  7. Execute N1QL : getN1QLResults
  8. getAndTouch : getAndTouchSingle

Usage

1. To setup Buckets

Parameters
  1. username : String

  2. password : String

  3. aryBuckets : array -> an array of bucket names in your couchbase cluster. each item(bucket name) is a string

  4. aryIps : array -> an array of IP addresses of your couchbase cluster. each item(ip) is a string

Example :
let db = require('@ossdeveloper/couchpromise').buckets
let buckets = {};
 
 let username = 'username';
 let password = 'password';
 let aryBuckets = ['default','bucket2'];
 let aryIPs = ['xxx.xxx.xxx.xxx','xxx.xxx.xxx.xxx','xxx.xxx.xxx.xxx'];
 
 db.setupBuckets(username, password,aryBuckets,aryIPs)
    .then((result) =>{
        
        if(result === true){
            
            buckets = db.getBuckets()
            
            console.log(buckets)
            
        }else{
            console.error(result)
        }
        
    })
    .catch((e) => {
        console.error(e)
    })
 

2. To insert a single record

let db = require('@ossdeveloper/couchpromise').buckets
let insertSingle = require('@ossdeveloper/couchpromise').insertSingle

cluster.openConnections(username, password,aryBuckets,aryIPs)
    .then((result) =>{
    
        if(result === true){
                        
            buckets = db.getBuckets()
            
            let strKey = 'uniqueKey'
            let objDocument = {"test": "test"}
            let objOptions = {}
            let objBucket = db.getBuckets()['default']
    
            insertSingle(strKey, objDocument, objBucket, objOptions)
            
                .then((result) => console.log(result))
                
                .catch((e) => console.log(e))
            
        }else{
            console.error(result)
        }
       
    
    })
    
    .catch((e) => console.error(e));

3. To upsert a single record

let db = require('@ossdeveloper/couchpromise').buckets
let upsertSingle = require('@ossdeveloper/couchpromise').upsertSingle

      

cluster.openConnections(username, password,aryBuckets,aryIPs)
    .then((result) =>{
    
        if(result === true){
                                    
            buckets = db.getBuckets()
            
            let strKey = 'uniqueKey'
            let objDocument = {"test": "test"}
            let objOptions = {}
            let objBucket = db.getBuckets()['default']
    
            upsertSingle(strKey, objDocument, objBucket, objOptions)
            
                .then((result) => console.log(result))
                
                .catch((e) => console.log(e))
            
        }else{
            console.error(result)
        }
    
    .catch((e) => {
        console.error(e);
    });

4. To replace a single record

let db = require('@ossdeveloper/couchpromise').buckets
let replaceSingle = require('@ossdeveloper/couchpromise').replaceSingle

cluster.openConnections(username, password,aryBuckets,aryIPs)

    .then((result) =>{
    
        if(result === true){
                                            
            buckets = db.getBuckets()
            
            let strKey = 'uniqueKey'
            let objDocument = {"test": "test"}
            let objOptions = {}
            let objBucket = db.getBuckets()['default']
    
            replaceSingle(strKey, objDocument, objBucket, objOptions)
                .then((result) => console.log(result))
                .catch((e) => console.error(e))
            
        }else{
            console.error(result)
        }
    

    })
    
    .catch((e) => console.error(e))

5. To remove a single record

let db = require('@ossdeveloper/couchpromise').buckets
let removeSingle = require('@ossdeveloper/couchpromise').removeSingle



cluster.openConnections(username, password,aryBuckets,aryIPs)
    
    .then((result) =>{
    
        if(result === true){
                                                    
            buckets = db.getBuckets()
            
            let strKey = 'uniqueKey'
            let objDocument = {"test": "test"}
            let objOptions = {}
            let objBucket = cluster.getBuckets()['default']
    
            removeSingle(strKey, objBucket)
                    
                .then((result) => console.log(result))
                
                .catch((e) => console.error(e))
            
        }else{
            console.error(result)
        }

    })
    
    .catch((e) => console.error(e))

6. To get a single record

let db = require('@ossdeveloper/couchpromise').buckets
let getSingle = require('@ossdeveloper/couchpromise').getSingle



cluster.openConnections(username, password,aryBuckets,aryIPs)
    
    .then((result) =>{
    
        if(result === true){
                                                                
            buckets = db.getBuckets()
            
            let strKey = 'uniqueKey'
            let objDocument = {"test": "test"}
            let objOptions = {}
            let objBucket = db.getBuckets()['default']
    
            getSingle(dbKey, objBucket)
            
                .then((result) => console.log(result))
                
                .catch((e) => console.error(e))
            
        }else{
            console.error(result)
        }
    
    })
    
    .catch((e) => {
        console.error(e);
    });

7. To execute N1QL Query and receive results

let db = require('@ossdeveloper/couchpromise').buckets
let getN1QLResults = require('@ossdeveloper/couchpromise').getN1QLResults

db.openConnections(username, password,aryBuckets,aryIPs)
 .then((result) =>{

    if(result === true){
    
        let strQuery = 'select * from default limit 10' // To get 10 records from default bucket
             
        let objBucket = db.getBuckets()['default']
            
        getN1QLResults(strQuery, objBucket)
             
            .then((result) => console.log(result))
                
            .catch((e) => console.error(e))        
    }else{
        console.error(result)
    }


})
 .catch((e) => {
     console.error(e);
 });

Multiple operations

8. To get Multiple records

let db = require('./index').buckets
let getSingle = require('@ossdeveloper/couchpromise').getSingle



cluster.openConnections(username, password,aryBuckets,aryIPs)
    
    .then((result) =>{
    
        if(result === true){
            let strKey = ['key1','key2']
            let objBucket = cluster.getBuckets()['default']
            
            getMulti(strKey,objBucket)
                .then((result) => {
                    console.log(result)
                })
                .catch((e) => {
                    console.error(e)
                })
            
        }else{
            console.error(result)
        }
    
    .catch((e) => {
        console.error(e);
    });

Happy Coding...