It would be great to have something similar to PouchDB.
Current key-value storage (AsyncStorage
) is definitely not enough to store and query data.
It would be great to have something similar to PouchDB.
Current key-value storage (AsyncStorage
) is definitely not enough to store and query data.
You may be able to use asyncstorage-down with PouchDB. Normally the method for using LevelDOWN adapters in Node.js is like so:
var PouchDB = require('pouchdb');
var db = new PouchDB('mydb', {db: require('asyncstorage-down')})
I haven't tested this, though.
Edit: well lucky you; a lot of work has been put into this recently: pouchdb-async-storage. Expect a blog post soon about how to get this working.
PouchDB is built for the browser, so it could probably work on React Native with a little effort.
Have you seen https://github.com/almost/react-native-sqlite ?
I had some Problems getting PouchDB working on react-native, but did not want to Install SQLLite. So I build an Adapter for Async Storage.
It Polyfills the missing Packages for React + Added an async Storage adapter base on "asyncstorage-down". Properly that helps.
I tried using Stockulus' async storage adaptor (https://github.com/stockulus/pouchdb-react-native) but had problems with replicating to a remote CouchDB server.
Now I am using React native SQLite Storage (https://github.com/andpor/react-native-sqlite-storage) and the PouchDB custom build pattern (https://pouchdb.com/2016/06/06/introducing-pouchdb-custom-builds.html) like this:
'use strict';
import PouchDB from 'pouchdb-core'
// POLYFILLS - adapted from https://github.com/pouchdb/pouchdb/issues/3787#issuecomment-234618747
global.Buffer = global.Buffer || require('buffer').Buffer;
global.atob = global.atob || require('atob');
global.btoa = global.btoa || require('btoa');
require('blob-polyfill');
import SQLite from 'react-native-sqlite-storage';
global.openDatabase = SQLite.openDatabase; // Expose for websql adapter
GLOBAL.openDatabase = SQLite.openDatabase;
PouchDB
.plugin(require('pouchdb-adapter-websql'))
.plugin(require('pouchdb-adapter-http'))
.plugin(require('pouchdb-replication'))
export default PouchDB
I know the global is ugly. We just started using it and replication is working better. We also had to polyfill a bunch of node stuff. This is used by pouchdb-core but not specified as a dependancy in pouchdb-core. Would love feedback.
Currently using these packages:
"events": "^1.1.1",
"pouchdb-adapter-http": "6.0.6",
"pouchdb-adapter-websql": "6.0.6",
"pouchdb-core": "6.0.6",
"pouchdb-replication": "6.0.6",
"atob": "^2.0.3",
"blob-polyfill": "^1.0.20150320",
"btoa": "^1.1.2",
"buffer": "^5.0.0",
Thanks
You can easily implement PouchDB on top on SQLLite - it has several configuration choices. You may need a SQLite Plugin to make it work. I have done this for Cordova in fact and it worked quite well. I believe PouchDB (which is pure JavaScript and therefore can be used out-of-the-box for ReactNative) has an adapter that works with the full featured SQLite3 Plugin.
React Native version of this plugin is available here:
https://github.com/andpor/react-native-sqlite-storage
The original Cordova plugin link can be found on the project github as well.
© 2022 - 2024 — McMap. All rights reserved.