nativescript-couchdb

0.6.23 • Public • Published

nativescript-couchdb

Nativescript plugin for couchdb A simple wrapper using nativescript http api to implement subset api compatible with PouchDB.

Install

tns plugin install nativescript-couchdb

API

constructor(couchdb_url, extraHeaders) Setup the database to connect to

put(doc)

  • doc string valid couchdb json doc with _id key
  • return promise

get(docId)

  • docId string document id
  • return promise

remove(doc)

  • doc json object couchdb json db or json with _id, _rev key
  • return promise

allDocs(options)

query(design_view)

  • design_view string eg /_design/design_name/_view/view_name will be design_name/view_name
  • return promise

Usage

 
import * as dialog from "ui/dialogs";
import { CouchDB } from "nativescript-couchdb";
 
let db = new CouchDB("https://couchdb.server/dbname", {
  "Authorization": "Basic base64\_encoded\_string"
});
let data = {
  _id: "hello",
  name: "world" 
}
 
 
// create and update
db.put(data)
  .then(res => dialog.alert("saved"))
  .catch(err => dialog.alert("Failed"));
 
// get data
db.get("hello")
  .then(res => dialog.alert(JSON.stringify(res)))
  .catch(err => dialog.alert("Data not found));
 
// delete doc
db.remove(data)
  .then(res => dialog.alert("Data deleted"))
  .catch(err => dialog.alert("Delete failed"));
 
// alldocs
db.allDocs(options)
  .then(res => dialog.alert(res))
  .catch(err => dialog.alert(err));
 
// query views
db.query("user/top_contributor", { group_level: 1, reduce: true })
  .then(res => dialog.alert(res))
  .catch(err => dialog.alert(err));
 

install

npm i nativescript-couchdb

Downloadsweekly downloads

6

version

0.6.23

license

Apache-2.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability