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
- A SQLite module
- rn-fetch-blob
npm install --save https://github.com/dj1993cse/pouchdb-adapters-rn.git
npm install --save-exact [email protected]
npm install --save https://github.com/dj1993cse/react-native-fetch-blob.git
react-native link rn-fetch-blob
react-native link react-native-sqlite-2
In Xcode, add libsqlite3.tbd
to your project's Build Phases
➜ Link Binary With Libraries
.
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'});
-
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,
-
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