cloudant-upsert
Version:
 
143 lines • 6.69 kB
JSON
{
"name": "cdimascio/cloudant-upsert",
"version": "0.1.4",
"libraries": {
"xv": "^1.1.25"
},
"title": "",
"branch": "",
"style": {
"name": "Default",
"componentSet": {
"nav": "nav/BasicNav",
"header": "header/BannerHeader",
"article": "article/BasicArticle",
"footer": "footer/BasicFooter"
},
"fontFamily": "-apple-system, BlinkMacSystemFont, sans-serif",
"fontWeight": 400,
"bold": 600,
"lineHeight": 1.5,
"typeScale": [
72,
48,
24,
20,
16,
14,
12
],
"monospace": "Menlo, monospace",
"heading": {
"fontFamily": null,
"fontStyle": null,
"fontWeight": 600,
"lineHeight": 1.25,
"textTransform": null,
"letterSpacing": null
},
"h0": {},
"h1": {},
"h2": {},
"h3": {},
"h4": {},
"h5": {},
"h6": {},
"alternativeText": {},
"space": [
0,
8,
16,
32,
48,
64,
96
],
"layout": {
"maxWidth": 1024,
"centered": false
},
"colors": {
"text": "#111",
"background": "#fff",
"primary": "#08e",
"secondary": "#059",
"highlight": "#e08",
"border": "#ddd",
"muted": "#eee"
},
"border": {
"width": 1,
"radius": 2
},
"link": {},
"button": {
"hover": {
"boxShadow": "inset 0 0 0 999px rgba(0, 0, 0, .125)"
}
},
"input": {},
"body": {
"margin": 0
},
"breakpoints": {
"xs": "@media screen and (max-width:40em)",
"sm": "@media screen and (min-width:40em)",
"md": "@media screen and (min-width:52em)",
"lg": "@media screen and (min-width:64em)"
}
},
"content": [
{
"component": "nav",
"links": [
{
"href": "https://github.com/cdimascio/cloudant-upsert",
"text": "GitHub"
},
{
"href": "https://npmjs.com/package/cloudant-upsert",
"text": "npm"
}
]
},
{
"component": "header",
"heading": "cloudant-upsert",
"subhead": "Adds an upsert to nodejs cloudant",
"children": [
{
"component": "ui/TweetButton",
"text": "cloudant-upsert: Adds an upsert to nodejs cloudant",
"url": ""
},
{
"component": "ui/GithubButton",
"user": "cdimascio",
"repo": "cloudant-upsert"
}
],
"text": "v0.9.4"
},
{
"component": "article",
"metadata": {
"source": "github.readme"
},
"html": "\n<p><img src=\"https://img.shields.io/badge/status-stable-green.svg\"> <img src=\"https://img.shields.io/badge/license-MIT-blue.svg\"></p>\n<p>A no-dependency module that adds an <code>upsert</code> function to the <a href=\"https://github.com/cloudant/nodejs-cloudant/blob/master/cloudant.js\">nodejs-cloudant</a> module.</p>\n<p>\n<img src=\"https://raw.githubusercontent.com/cdimascio/cloudant-upsert/master/assets/cloudant-upsert.png\">\n</p>\n\n<h2>Install</h2>\n<pre>npm install cloudant-upsert</pre><h2>Usage</h2>\n<p>The following adds the <code>upsert</code> function to a <code>cloudant</code> instance</p>\n<pre><span class=\"hljs-keyword\">var</span> Cloudant = <span class=\"hljs-built_in\">require</span>(<span class=\"hljs-string\">'@cloudant/cloudant'</span>);\n<span class=\"hljs-keyword\">var</span> cloudant = Cloudant(<span class=\"hljs-string\">'<YOUR_CLOUDANT_URI>'</span>);\n<span class=\"hljs-built_in\">require</span>(<span class=\"hljs-string\">'cloudant-upsert'</span>)(cloudant);</pre><h2>Examples</h2>\n<h4>Promises</h4>\n<p>In the example below <code>prevdoc</code> contains <code>null</code> or the previous doc</p>\n<pre>cloudant.db.use(<span class=\"hljs-string\">'mydb'</span>).upsert(<span class=\"hljs-string\">'carmine'</span>, prevdoc => ({\n <span class=\"hljs-string\">"text"</span>: <span class=\"hljs-string\">"Woop Woop! We're using promises"</span>,\n }))\n .then(<span class=\"hljs-function\"><span class=\"hljs-params\">r</span> =></span> <span class=\"hljs-built_in\">console</span>.log(<span class=\"hljs-string\">'result'</span>, r))\n .catch(<span class=\"hljs-function\"><span class=\"hljs-params\">e</span> =></span> <span class=\"hljs-built_in\">console</span>.log(<span class=\"hljs-string\">'error'</span>, e.message));</pre><h4>Callbacks</h4>\n<p>In the example below <code>prevdoc</code> contains <code>null</code> or the previous doc</p>\n<pre>cloudant.db.use(<span class=\"hljs-string\">'mydb'</span>).upsert(<span class=\"hljs-string\">'carmine'</span>, prevdoc => ({\n <span class=\"hljs-string\">"text"</span>: <span class=\"hljs-string\">"Woop! Woop! We're using callbacks"</span>\n }), (err, data) => {\n <span class=\"hljs-keyword\">if</span> (err) <span class=\"hljs-built_in\">console</span>.log(<span class=\"hljs-string\">'error'</span>, err.reason)\n <span class=\"hljs-keyword\">else</span> <span class=\"hljs-built_in\">console</span>.log(<span class=\"hljs-string\">'data'</span>, data)\n })</pre><h2>API</h2>\n<h3>Promise API</h3>\n<h3><code>upsert(id, function(prevdoc)</code>)</h3>\n<table>\n<thead>\n<tr>\n<th>param</th>\n<th>description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>id</code></td>\n<td>The document id to upsert</td>\n</tr>\n<tr>\n<td><code>function(prevdoc): doc</code></td>\n<td>A function that provides the previous document (or null when inserting a new doc) as input. You must return the document to upsert.</td>\n</tr>\n</tbody>\n</table>\n<h3>Callback API</h3>\n<h3><code>upsert(id, function(prevdoc), function(err, res)}</code></h3>\n<table>\n<thead>\n<tr>\n<th>param</th>\n<th>description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>id</code></td>\n<td>The document id to upsert</td>\n</tr>\n<tr>\n<td><code>function(prevdoc): doc</code></td>\n<td>A function that provides the previous document (or null when inserting a new doc) and returns a new document to upsert</td>\n</tr>\n<tr>\n<td><code>function(err, res): void</code></td>\n<td>A Node.js error first callback</td>\n</tr>\n</tbody>\n</table>\n<h2>License</h2>\n<p><a href=\"LICENSE\">MIT</a></p>\n"
},
{
"component": "footer",
"links": [
{
"href": "https://github.com/cdimascio/cloudant-upsert",
"text": "GitHub"
},
{
"href": "https://github.com/cdimascio",
"text": "cdimascio"
}
]
}
]
}