
Product
Introducing Custom Tabs for Org Alerts
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.
couchbase-structures
Advanced tools
compound data structures for couchbase built in node.js
This project creates helpful wrappers around normal couchbase documents to allow you to create more complex objects. Being couchbase, this means that your objects will be redundant and distributed!
Note that this code it likley to be very buggy and slow. You were warned!
npm install couchbase-structures
var couchbase = require("couchbase");
var CouchbaseStructures = require("couchbase-structures");
var couchbase_config = {
debug : false,
hosts : [ "localhost:8091" ],
password : "password",
bucket : "demo",
user : "demo"
}
couchbase.connect(couchbase_config, function(err, bucket){
if(err){
console.log(error);
process.exit();
}else{
// arrays
var arr = new CouchbaseStructures.array("myArray", bucket);
arr.create(function(err){
arr.set(0, {'name': 'array thing 1'}, function(err){
arr.set(5, {'name': 'array thing 5'}, function(err){
arr.length(function(err, length){
console.log(length) // 6
arr.get(5, function(err, doc){
console.log(doc); // doc = {'name': 'array thing 5'}
});
arr.get(3, function(err, doc){
console.log(doc); // doc = null
});
});
});
});
});
// queues
var queue = new CouchbaseStructures.queue("myQueue", bucket);
queue.create(function(err){
queue.push({'name': 'queue thing #1'}, function(err){
queue.push({'name': 'queue thing #2'}, function(err){
queue.length(function(err, length){
console.log(length) // 2
queue.pop(function(err, doc){
console.log(doc); // doc = {'name': 'queue thing #1'}
});
queue.pop(function(err, doc){
console.log(doc); // doc = {'name': 'queue thing #2'}
});
});
});
});
});
// hash
var hash = new CouchbaseStructures.hash("myHash", bucket);
hash.create(function(err){
hash.set('key_1', {'name': 'hash thing #1'}, function(err){
hash.set('key_3', {'name': 'hash thing #3'}, function(err){
hash.length(function(err, length){
console.log(length) // 2
hash.get('key_3', function(err, doc){
console.log(doc) // {'name': 'hash thing #3'}
});
hash.get('some_other_key', function(err, doc){
console.log(doc) // null
});
});
});
});
});
}
});
You can run these tests from demo.js, which is included in this project.
The only configuration options are key seperators and timeout options. You can overide the defaults like so:
var CouchbaseStructures = require("couchbase-structures");
CouchbaseStructures.structure.prototype.counterPrefix = function(){ return "_counter"; }
CouchbaseStructures.structure.prototype.createPlaceholder = function(){ return "PLACEHOLDER"; }
CouchbaseStructures.structure.prototype.keySeperator = function(){ return ":"; }
CouchbaseStructures.structure.prototype.lockDuration = function(){ return 10; } // seconds
CouchbaseStructures.structure.prototype.lockAttempts = function(){ return 10; }
CouchbaseStructures.structure.prototype.lockWaitSleep = function(){ return 100; } // miliseconds
All of the types defined in this project inherit from structure. This class holds the primitives for getting and setting child documents, updating metadata, etc. The public methods are listed here:
bucket object returned from esablishing a connectionout of bounds errornull values)null if the queue is emptyNote that these hashes differ from normal couchbase documents in that they will allow you to update one key of the hash indepentandly from the the entirety of the document.
npm test should be all you need. Be sure that your couchbase settings match what is defined in the test:
var couchbase_config = {
"debug" : false,
"hosts" : [ "localhost:8091" ],
"password" : "password",
"bucket" : "test",
"user" : "test"
}
FAQs
compound data structures for couchbase built in node.js
The npm package couchbase-structures receives a total of 2 weekly downloads. As such, couchbase-structures popularity was classified as not popular.
We found that couchbase-structures 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.

Product
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.