{"id":17148096,"url":"https://github.com/evantahler/couchbase-structures","last_synced_at":"2025-07-05T11:40:21.417Z","repository":{"id":8759463,"uuid":"10441512","full_name":"evantahler/couchbase-structures","owner":"evantahler","description":"compound data structures for couchbase built in node.js","archived":false,"fork":false,"pushed_at":"2014-01-07T19:20:23.000Z","size":300,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-14T09:03:18.062Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evantahler.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-02T20:08:07.000Z","updated_at":"2016-11-15T01:06:41.000Z","dependencies_parsed_at":"2022-09-08T23:50:19.653Z","dependency_job_id":null,"html_url":"https://github.com/evantahler/couchbase-structures","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/evantahler/couchbase-structures","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evantahler%2Fcouchbase-structures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evantahler%2Fcouchbase-structures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evantahler%2Fcouchbase-structures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evantahler%2Fcouchbase-structures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evantahler","download_url":"https://codeload.github.com/evantahler/couchbase-structures/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evantahler%2Fcouchbase-structures/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263735359,"owners_count":23503495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T21:27:10.631Z","updated_at":"2025-07-05T11:40:21.382Z","avatar_url":"https://github.com/evantahler.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Couchbase Structures\n*compound data structures for couchbase built in node.js*\n\n[![Build Status](https://travis-ci.org/evantahler/couchbase-structures.png?branch=master)](https://travis-ci.org/evantahler/couchbase-structures)\n\nThis 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!\n\nNote that this code it likley to be very buggy and slow.  You were warned!\n\n- **[GitHub](https://github.com/evantahler/couchbase-structures)**\n- **[NPM](https://npmjs.org/package/couchbase-structures)**\n\n## Install\n\n`npm install couchbase-structures`\n\n## Example\n```javascript\nvar couchbase = require(\"couchbase\"); \nvar CouchbaseStructures = require(\"couchbase-structures\");\n\nvar couchbase_config = {\n  debug    : false,\n  hosts    : [ \"localhost:8091\" ],\n  password : \"password\",\n  bucket   : \"demo\",\n  user     : \"demo\"\n}\n\ncouchbase.connect(couchbase_config, function(err, bucket){\n  if(err){ \n    console.log(err);\n    process.exit();\n  }else{\n\n    // arrays\n    var arr = new CouchbaseStructures.array(\"myArray\", bucket);\n    arr.create(function(err){\n      arr.set(0, {'name': 'array thing 1'}, function(err){\n        arr.set(5, {'name': 'array thing 5'}, function(err){\n          arr.length(function(err, length){\n            console.log(length) // 6\n            arr.get(5, function(err, doc){\n              console.log(doc); // doc = {'name': 'array thing 5'}\n            });\n            arr.get(3, function(err, doc){\n              console.log(doc); // doc = null\n            });\n          });\n        });\n      });\n    });\n\n    // queues\n    var queue = new CouchbaseStructures.queue(\"myQueue\", bucket);\n    queue.create(function(err){\n      queue.push({'name': 'queue thing #1'}, function(err){\n        queue.push({'name': 'queue thing #2'}, function(err){\n          queue.length(function(err, length){\n            console.log(length) // 2\n            queue.pop(function(err, doc){\n              console.log(doc); // doc = {'name': 'queue thing #1'}\n            });\n            queue.pop(function(err, doc){\n              console.log(doc); // doc = {'name': 'queue thing #2'}\n            });\n          });\n        });\n      });\n    });\n\n    // hash\n    var hash = new CouchbaseStructures.hash(\"myHash\", bucket);\n    hash.create(function(err){\n      hash.set('key_1', {'name': 'hash thing #1'}, function(err){\n        hash.set('key_3', {'name': 'hash thing #3'}, function(err){ \n          hash.length(function(err, length){\n            console.log(length) // 2\n            hash.get('key_3', function(err, doc){\n              console.log(doc) // {'name': 'hash thing #3'}\n            });\n            hash.get('some_other_key', function(err, doc){\n              console.log(doc) // null\n            }); \n          });\n        });\n      });\n    });\n\n  }\n});\n```\n\nYou can run these tests from `demo.js`, which is included in this project.\n\n## Config\n\nThe only configuration options are key seperators and timeout options.  You can overide the defaults like so:\n\n```javascript\nvar CouchbaseStructures = require(\"couchbase-structures\");\nCouchbaseStructures.structure.prototype.counterPrefix = function(){ return \"_counter\"; }\nCouchbaseStructures.structure.prototype.createPlaceholder = function(){ return \"PLACEHOLDER\"; }\nCouchbaseStructures.structure.prototype.keySeperator = function(){ return \":\"; }\nCouchbaseStructures.structure.prototype.lockDuration = function(){ return 10; } // seconds\nCouchbaseStructures.structure.prototype.lockAttempts = function(){ return 10; }\nCouchbaseStructures.structure.prototype.lockWaitSleep = function(){ return 100; } // miliseconds\n```\n\n## DSL\n\n### Structure\nAll 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:\n\n#### object = new structure('name', bucket)\n\n* bucket is a couchbase `bucket` object returned from esablishing a connection\n* the name should be unique\n\n#### object.create(callback(err))\n\n* used to create a new object.  Will fail if the document already exists\n\n#### object.load(callback(err, metadata))\n\n* used to load in a previously created object\n\n#### object.destroy(callback(err))\n\n* used to delete an object and all children\n\n### Array\n\n#### array.set(index, data, callback(err))\n\n* set a key in an array\n* an id can be set (0 -\u003e infinity).  This will increase the size of the array if needed\n\n#### array.get(index, callback(err, data))\n\n* return an element of an array\n* possible to get an `out of bounds` error\n\n#### array.length(callback(err, length))\n\n* get the size of the array (including `null` values)\n\n#### array.getAll(callback(err, data))\n\n* get every item in the array\n* this is likely to be very slow\n\n### Queue (list)\n\n#### queue.push(index, data, callback(err))\n\n* push a document to the end of the queue\n\n#### queue.pop(index, callback(err, data))\n\n* return and remove the first element from a queue\n* possible to `null` if the queue is empty\n\n#### queue.length(callback(err, length))\n\n* get the size of the queue\n\n#### queue.getAll(callback(err, data))\n\n* get every item in the queue\n* this is likely to be very slow\n\n### Hash\nNote 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.\n\n#### hash.set(key, data, callback(err))\n\n* set a key in an hash\n\n#### hash.get(key, callback(err, data))\n\n* return an element of a hash\n* null will be returned if the key is not set\n\n#### hash.length(callback(err, length))\n\n* get the count of the set keys in a hash\n\n#### hash.getAll(callback(err, data))\n\n* get every item in the hash\n* this is likely to be very slow\n\n## Testing\n\n`npm test` should be all you need.  Be sure that your couchbase settings match what is defined in the test:\n```javascript\nvar couchbase_config = {\n  \"debug\" : false,\n  \"hosts\" : [ \"localhost:8091\" ],\n  \"password\" : \"password\",\n  \"bucket\" : \"test\",\n  \"user\" : \"test\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevantahler%2Fcouchbase-structures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevantahler%2Fcouchbase-structures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevantahler%2Fcouchbase-structures/lists"}