@nowarzz/pouchdb-adapters-rn
v1.0.6
Published
PouchDB adapters for ReactNative using HTTP (e.g. a remote CouchDB) and SQLite as its data store
Downloads
3
Maintainers
Readme
pouchdb-adapters-rn
PouchDB adapter for ReactNative using HTTP (e.g. a remote CouchDB or CouchDB-like database) or SQLite as its data store.
This package has made changes in pouchdb-adapter-websql and pouch-adapter-http for compatibility with react-native.
It supports PouchDB till version 7.0.0
Prerequisites
- A SQLite module
- rn-fetch-blob
Installation
npm install --save-exact pouchdb-adapters-rn
npm install --save-exact [email protected]
npm install --save https://github.com/kkbhav/react-native-fetch-blob.git#work
react-native link rn-fetch-blob
react-native link react-native-sqlite-2
- Extra step for iOS
In Xcode, add libsqlite3.tbd
to your project's Build Phases
➜ Link Binary With Libraries
.
Usage
import PouchDB from 'pouchdb-adapters-rn';
var db = new PouchDB('mydb', { adapter: 'pouchdb-adapters-rn'});
// or
var remote = new PouchDB('http://127.0.0.1:5984/mydb');
// or
var remote1 = new PouchDB('http://127.0.0.1:5984/mydb', { adapter: 'pouchdb-adapters-rn-http'});
- Updated API For RemoteDB
All API's calls will return attachment as base64(default) string or a file-uri
remote.getAttachment(docId, attachmentId, options, callback)
- extra options values(optional)
- path: string, Path to save the file(optional, if not passed base64 string will be returned)
- name: name of the file(optional, only used when file parameter is passed)
- extra options values(optional)
remote.get(docId, options, callback)
- extra options values(optional)
- path: string, Path to save the file(optional, if not passed base64 string will be returned)
- extra options values(optional)
remote.putAttachment(docId, attachmentId, [rev], attachment, type, [callback])
- attachment: file-uri or base64(cannot process blob types)
remote.put(doc) or remote.bulkDocs(docs)
- accepts file-uri or base64 in attachment data,
Example doc
const doc = { _id: 'somethings', _attachments: { 'photo': { 'content-type': 'image/jpg', 'data': '/Users/pouch/image.jpg', }, } } remote.put(doc);
- accepts file-uri or base64 in attachment data,
- Updated API For LocalDB
All API's calls will return attachment as base64(default) string or a file-uri
db.getAttachment(docId, attachmentId, options, callback)
- extra options values(optional)
- path: boolean to return attachment as fileUri(optional, if not passed base64 string will be returned)
- extra options values(optional)
db.allDocs(options)
- extra options values(optional)
- path: boolean to return attachment as fileUri(optional, if not passed base64 string will be returned)
- extra options values(optional)
db.get(docId)
- will return attachment as base64 if requested
db.putAttachment(docId, attachmentId, [rev], attachment, type, [callback])
- attachment: file-uri or base64(cannot process blob types)
db.bulkDocs(docs)
- accepts path in attachment data, Example docs
const docs = [{ _id: 'somethings', _attachments: { 'photo': { 'content-type': 'image/jpg', 'data': '/Users/pouch/image.jpg', }, } }] db.bulkDocs(docs);
db.put(doc)
- accepts path in attachment data, Example docs
const doc = { _id: 'somethings', _attachments: { 'photo': { 'content-type': 'image/jpg', 'data': '/Users/pouch/image.jpg', }, } } db.put(doc);
For full API documentation and guides on PouchDB, see PouchDB.com. For details on PouchDB sub-packages, see the Custom Builds documentation.
Supports PouchDB till version 7.0.0