
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
couchdbjs is node.js client for couchdb.
$ npm install couchdbjs --save
const Couchdbjs = require('couchdbjs');
const db = new Couchdbjs(dbname, options, callback);
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.
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 and port 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
}));
// not recommended
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.
// recommended
Couchdbjs.createDB({
protocol: 'http:',
hostname: 'localhost',
port: 5984,
db: 'dbanme'
}, function(err, data)=>{
if (err) console.error(err);
else console.log(data);
});
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);
});
db.getAllDocs(function(err, data) {
if (err) console.error(err);
else console.log(data);
});
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);
});
db.getDoc(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);
});
db.updateDoc(id, doc, cb);
id
, doc
, cb
are id of document to be updated, document object with filed to be updated and callback function with parameters err
and data
respectively.
Example
Suppose this a document already present
{
'id': 'id_doc',
'_rev': '1-1357',
'a': 1,
'b': 'asd'
}
If the following function is used to update the document
db.upadteDoc('id_doc', {b: 'cs', c: 5}, function(err, data) {});
then the final document will be
{
'id': 'id_doc',
'_rev': '2-2468',
'a': 1,
'b': 'cs',
'c': 5
}
After that if the following function is used to update the document
db.upadteDoc('id_doc', {b: 'cse', a: undefined}, function(err, data) {});
then the final document will be
{
'id': 'id_doc',
'_rev': '3-3579',
'b': 'cse',
'c': 5
}
To update whole document by overwriting the existing one use
db.createDoc(id, doc, cb);
with _rev
field in the doc
document.
db.deleteDoc(id, function(err, data) {
if (err) console.error(err);
else console.log(data);
});
db.attachFileToDoc(id, rev, file, cb);
Example
db.attachFileToDoc('id_doc', '3-3579', {
name: 'pic.jpg',
path: '/home/user/image.jpg'
mimetype: 'image/jpeg'
}, function(err, data) {
if (err) console.error(err);
else console.log(data);
});
Here the file gets uploaded to http://localhost:5984/db_name/id_doc/pic.jpg.
db.deleteAttachment(id, rev, attachmentName, cb);
Example
db.attachFileToDoc('id_doc', '4-1579', 'pic.jpg', function(err, data) {
if (err) console.error(err);
else console.log(data);
});
FAQs
A node client for couchdb.
The npm package couchdbjs receives a total of 0 weekly downloads. As such, couchdbjs popularity was classified as not popular.
We found that couchdbjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.