{"id":15595713,"url":"https://github.com/cdimascio/cloudant-upsert","last_synced_at":"2025-04-24T06:33:34.490Z","repository":{"id":57200704,"uuid":"91205911","full_name":"cdimascio/cloudant-upsert","owner":"cdimascio","description":"A no-dependency module that adds 'upsert' to Node.js Cloudant","archived":false,"fork":false,"pushed_at":"2018-09-24T00:56:34.000Z","size":88,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T07:51:14.126Z","etag":null,"topics":["cloudant","ibm-cloud","nodejs","upsert"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cdimascio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-13T22:17:16.000Z","updated_at":"2021-02-23T23:32:52.000Z","dependencies_parsed_at":"2022-09-16T15:11:46.227Z","dependency_job_id":null,"html_url":"https://github.com/cdimascio/cloudant-upsert","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fcloudant-upsert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fcloudant-upsert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fcloudant-upsert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fcloudant-upsert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdimascio","download_url":"https://codeload.github.com/cdimascio/cloudant-upsert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250579331,"owners_count":21453459,"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":["cloudant","ibm-cloud","nodejs","upsert"],"created_at":"2024-10-03T01:01:12.671Z","updated_at":"2025-04-24T06:33:34.467Z","avatar_url":"https://github.com/cdimascio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cloudant-upsert\n\n![](https://img.shields.io/badge/status-stable-green.svg) ![](https://img.shields.io/badge/license-MIT-blue.svg)\n\nA no-dependency module that adds an `upsert` function to the [nodejs-cloudant](https://github.com/cloudant/nodejs-cloudant/blob/master/cloudant.js) module.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/cdimascio/cloudant-upsert/master/assets/cloudant-upsert.png\"/\u003e\n\u003c/p\u003e\n\n## Install\n\n```shell\nnpm install cloudant-upsert\n```\n\n## Usage\n\nThe following adds the `upsert` function to a `cloudant` instance\n\n```javascript\nvar Cloudant = require('@cloudant/cloudant');\nvar cloudant = Cloudant('\u003cYOUR_CLOUDANT_URI\u003e');\nrequire('cloudant-upsert')(cloudant);\n```\n\n## Examples\n\n#### Promises\n\nIn the example below `prevdoc` contains `null` or the previous doc\n\n```javascript\ncloudant.db.use('mydb').upsert('carmine', prevdoc =\u003e ({\n    \"text\": \"Woop Woop! We're using promises\",\n  }))\n  .then(r =\u003e console.log('result', r))\n  .catch(e =\u003e console.log('error', e.message));\n```\n\n#### Callbacks\n\nIn the example below `prevdoc` contains `null` or the previous doc\n\n```javascript\ncloudant.db.use('mydb').upsert('carmine', prevdoc =\u003e ({\n    \"text\": \"Woop! Woop! We're using callbacks\"\n  }), (err, data) =\u003e {\n    if (err) console.log('error', err.reason)\n    else console.log('data', data)\n  })\n```\n\n## API\n\n### Promise API\n### `upsert(id, function(prevdoc)`)\n\n| param | description |\n| ------------- | ------------- |\n| `id`  | The document id to upsert  |\n| `function(prevdoc): doc `  | A function that provides the previous document (or null when inserting a new doc) as input. You must return the document to upsert.  |\n\n\n### Callback API\n### `upsert(id, function(prevdoc), function(err, res)}`\n\n| param | description |\n| ------------- | ------------- |\n| `id`  | The document id to upsert  |\n| `function(prevdoc): doc`  | A function that provides the previous document (or null when inserting a new doc) and returns a new document to upsert  |\n| `function(err, res): void`  | A Node.js error first callback |\n\n\n## License\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdimascio%2Fcloudant-upsert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdimascio%2Fcloudant-upsert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdimascio%2Fcloudant-upsert/lists"}