{"id":15321833,"url":"https://github.com/eldimious/couchbase-server-promises","last_synced_at":"2025-04-15T02:37:21.252Z","repository":{"id":22128119,"uuid":"95298279","full_name":"eldimious/couchbase-server-promises","owner":"eldimious","description":"Couchbase-server-promises library wraps couchbase's callback functions for handling the result of the asynchronous operations, with Bluebird promises to provide a convenient, promise-based interface.","archived":false,"fork":false,"pushed_at":"2023-02-28T13:47:56.000Z","size":804,"stargazers_count":6,"open_issues_count":13,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-14T09:41:13.042Z","etag":null,"topics":["bluebird","couchbase","couchbase-server","couchbase-wrapper","db-wrapper","promise-wrapper","promises"],"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/eldimious.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-24T13:09:50.000Z","updated_at":"2022-02-04T18:47:25.000Z","dependencies_parsed_at":"2024-10-01T09:13:18.332Z","dependency_job_id":"99c36a37-4804-47a6-884f-a0cd8216894f","html_url":"https://github.com/eldimious/couchbase-server-promises","commit_stats":{"total_commits":90,"total_committers":1,"mean_commits":90.0,"dds":0.0,"last_synced_commit":"068c23a7752278aaf540ddf5a2eac8bbba3d6a77"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fcouchbase-server-promises","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fcouchbase-server-promises/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fcouchbase-server-promises/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fcouchbase-server-promises/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eldimious","download_url":"https://codeload.github.com/eldimious/couchbase-server-promises/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248995100,"owners_count":21195497,"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":["bluebird","couchbase","couchbase-server","couchbase-wrapper","db-wrapper","promise-wrapper","promises"],"created_at":"2024-10-01T09:13:15.172Z","updated_at":"2025-04-15T02:37:21.228Z","avatar_url":"https://github.com/eldimious.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# couchbase-server-promises\n\n\u003e A promise-based asynchronous library for Couchbase and node.js.\n\nThe [Official Couchbase Node.js Client Library](https://www.npmjs.com/package/couchbase) provides only callback functions to handle the result of the asynchronous operations. This `couchbase-server-promises` library wraps those callback functions with [Bluebird](https://www.npmjs.com/package/bluebird) promises to provide a convenient, promise-based interface.\n\n## Usage\n\nFirst, install `couchbase-server-promises` as a dependency:\n\n```shell\nnpm install --save couchbase-server-promises\n```\n\nIn order to init it, you should use a config. The config should have a structure like this:\n\n```javascript\nconst config = {\n  cluster: [ 'couchbase://127.0.0.1:8091' ],\n  buckets: [\n    {\n      bucket: 'customers',\n    },\n    {\n      bucket: 'stats',\n    }, \n    {\n      bucket: 'users'\n    }\n  ],\n  user: 'testUser',\n  password: 'testPassword',\n};\n```\n\nas `buckets` we add all couchbase's bucket(name\u0026password(password is not required)), that we have in our cluster. Also you can specify multiple hosts(clusters) in the connection string(cluster's array in config). To specify multiple hosts, separate them using a comma, for example: `cluster: [couchbase://127.0.0.1:8091,couchbase://127.0.0.1:8092]`. Also, you can specify `operationTimeout` for each bucket(not required).\n\nThen, reference it in your code file:\n\n```javascript\nconst couchbasePromisesWrapper = require('couchbase-server-promises')(config);\n```\n\nUse the methods of the `couchbasePromisesWrapper` class to manage documents stored in your Couchbase database directly by their document identifiers:\n\n## Exported Methods:\n\n- `getDoc(bucket, docId)`\n- `upsertDoc(bucket, docId, newDoc)`\n- `insertDoc(bucket, docId, newDoc)`\n- `replaceDoc(bucket, docId, newDoc)`\n- `removeDoc(bucket, docId)`\n- `getMultiDocs(bucket, [ docIds ])`\n- `query(bucket, query)`\n- `getBucketManager(bucket)`: Returns **bucket.manager**\n- `getConnectedBuckets()`: Returns array of connected buckets\n- `disconnectBucket(bucket)`: Disconnects from bucket\n\nwhere:\n`bucket`: is the name of bucket we want to manage doc, \n`docId`: is the doc's name we want to manage,\n`newDoc`: is the doc's struct that we want to store in `docId`\n\n## Example\n\n1) **Get doc** with name `user:test` from `customers` bucket:\n\n```JavaScript\ntry {\n  const doc = await couchbasePromisesWrapper.getDoc('customers', 'user:test');\n  /*code*/\n} catch(error) {\n  /*code*/\n}\n```\n\n2) **Get doc** with name `statistics:test` from `stats` bucket:\n\n```JavaScript\ntry {\n  const doc = await couchbasePromisesWrapper.getDoc('stats', 'statistics:test');\n  /*code*/\n} catch(error) {\n  /*code*/\n}\n```\n\n3) Update doc with name `statistics:test` from `stats` bucket with a new object called `newTestValue`:\n\n```JavaScript\ntry {\n  const doc = await couchbasePromisesWrapper.upsertDoc('stats', 'statistics:test', newTestValue)\n  /*code*/\n} catch(error) {\n  /*code*/\n};\n```\n4) Remove doc with name `statistics:test` from `stats` bucket:\n\n```JavaScript\ntry {\n  const doc = await couchbasePromisesWrapper.removeDoc('stats', 'statistics:test')\n  /*code*/\n} catch(error) {\n  /*code*/\n};\n```\n\n5) Replace doc with name `statistics:test` from `stats` bucket with a new object called `newTestValue`:\n\n```JavaScript\ntry {\n  const doc = await couchbasePromisesWrapper.replaceDoc('stats', 'statistics:test', newTestValue)\n  /*code*/\n} catch(error) {\n  /*code*/\n};\n```\n\n6) Add new doc with name `statistics:test` in `stats` bucket with value: `newTestValue`:\n\n```JavaScript\ntry {\n  const doc = await couchbasePromisesWrapper.insertDoc('stats', 'statistics:test', newTestValue)\n  /*code*/\n} catch(error) {\n  /*code*/\n};\n```\n\n7) Get list of docs(multi) with name `statistics:test1`, `statistics:test2` and `statistics:test3`:\n\n```JavaScript\ntry {\n  const docs = await couchbasePromisesWrapper.getMultiDocs('stats', [\n    'statistics:test1',\n    'statistics:test2',\n    'statistics:test3',\n  ])\n  /*code*/\n} catch(error) {\n  /*code*/\n};\n```\n\n\n9) Make query to `stats` bucket using a `view`:\n\n```JavaScript\nconst view = couchbasePromisesWrapper.ViewQuery\n  .from('testView', 'test')\n  .range(startkey, endkey)\n  .order(order)\n  .reduce(false)\n  .limit(24)\n  .skip(10);\n  \ncouchbasePromisesWrapper.query('stats', view)\n.then(doc =\u003e {\n  /*code*/\n})\n.catch(error =\u003e {\n  /*code*/\n});\n```\n\n8) Make query to `stats` bucket using a `N1qlQuery`:\n\n```JavaScript\nconst sqlQuery = couchbasePromisesWrapper.N1qlQuery.fromString(`\n  SELECT * FROM \\`stats\\`\n  WHERE type = \"test\";\n`);\n  \ncouchbasePromisesWrapper.query('stats', sqlQuery)\n.then(doc =\u003e {\n  /*code*/\n})\n.catch(error =\u003e {\n  /*code*/\n});\n```\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feldimious%2Fcouchbase-server-promises","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feldimious%2Fcouchbase-server-promises","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feldimious%2Fcouchbase-server-promises/lists"}