- Ensure node-gyp is installed globally(npm install -g node-gyp)
- node.js version >= 10.13.0
- npm install --save @ossdeveloper/couchpromise
Above command installs couchbase and 'q' promise library as dependencies.
- Your couchbase cluster username is 'username' and password is 'password'
- You have a bucket named 'default' in your couchbase cluster
** You can use this library like regular couchbase node.js sdk and, use below methods for promises **
- Settingup buckets(DB connection) : setupBuckets
- insert : insertSingle
- upsert : upsertSingle
- replace : replaceSingle
- remove : removeSingle
- get : getSingle
- Execute N1QL : getN1QLResults
- getAndTouch : getAndTouchSingle
-
username : String
-
password : String
-
aryBuckets : array -> an array of bucket names in your couchbase cluster. each item(bucket name) is a string
-
aryIps : array -> an array of IP addresses of your couchbase cluster. each item(ip) is a string
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)
})
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));
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);
});
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))
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))
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);
});
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);
});
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);
});