New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cloudant-upsert

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cloudant-upsert

![](https://img.shields.io/badge/status-stable-green.svg) ![](https://img.shields.io/badge/license-MIT-blue.svg)

  • 0.11.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
148
increased by17.46%
Maintainers
1
Weekly downloads
 
Created
Source

cloudant-upsert

A no-dependency module that adds an upsert function to the nodejs-cloudant module.

Install

npm install cloudant-upsert

Usage

The following adds the upsert function to a cloudant instance

var Cloudant = require('@cloudant/cloudant');
var cloudant = Cloudant('<YOUR_CLOUDANT_URI>');
require('cloudant-upsert')(cloudant);

Examples

Promises

In the example below prevdoc contains null or the previous doc

cloudant.db.use('mydb').upsert('carmine', prevdoc => ({
    "text": "Woop Woop! We're using promises",
  }))
  .then(r => console.log('result', r))
  .catch(e => console.log('error', e.message));
Callbacks

In the example below prevdoc contains null or the previous doc

cloudant.db.use('mydb').upsert('carmine', prevdoc => ({
    "text": "Woop! Woop! We're using callbacks"
  }), (err, data) => {
    if (err) console.log('error', err.reason)
    else console.log('data', data)
  })

API

Promise API

upsert(id, function(prevdoc))

paramdescription
idThe document id to upsert
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.

Callback API

upsert(id, function(prevdoc), function(err, res)}

paramdescription
idThe document id to upsert
function(prevdoc): docA function that provides the previous document (or null when inserting a new doc) and returns a new document to upsert
function(err, res): voidA Node.js error first callback

License

MIT

Keywords

FAQs

Package last updated on 24 Sep 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc