- Notifications
You must be signed in to change notification settings - Fork32
PouchDB adapter using ReactNative SQLite as its backing store
License
craftzdog/pouchdb-adapter-react-native-sqlite
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
PouchDB adapter usingop-sqlite as its backing store on React Native.It's much faster than AsyncStorage.
As of v4.0.0, it no longer requires@craftzdog/pouchdb-adapter-websql-core
.It now directly uses op-sqlite, so it's more efficient.
yarn add @op-engineering/op-sqlite react-native-quick-crypto @craftzdog/react-native-buffer @craftzdog/pouchdb-errors
Create ashim.ts
file like so:
import{install}from'react-native-quick-crypto'install()
Configure babel to use the shim modules. First, you need to installbabel-plugin-module-resolver
.
yarn add --dev babel-plugin-module-resolver
Then, in yourbabel.config.js
, add the plugin to swap thecrypto
,stream
andbuffer
dependencies:
plugins:[['module-resolver',{extensions:['.tsx','.ts','.js','.json'],alias:{crypto:'react-native-quick-crypto',stream:'readable-stream',buffer:'@craftzdog/react-native-buffer','pouchdb-errors':'@craftzdog/pouchdb-errors'},},],],
Then restart your bundler usingyarn start --reset-cache
.
Now it's ready to use PouchDB!
yarn add pouchdb-core pouchdb-mapreduce pouchdb-replication pouchdb-adapter-http pouchdb-adapter-react-native-sqlite
Createpouchdb.ts
:
importPouchDBfrom'pouchdb-core'importHttpPouchfrom'pouchdb-adapter-http'importreplicationfrom'pouchdb-replication'importmapreducefrom'pouchdb-mapreduce'importsqliteAdapterfrom'pouchdb-adapter-react-native-sqlite'exportdefaultPouchDB.plugin(HttpPouch).plugin(replication).plugin(mapreduce).plugin(sqliteAdapter)
importPouchDBfrom'./pouchdb'constpouch=newPouchDB('mydb',{adapter:'react-native-sqlite',// Other options})
You can specify the following options in the PouchDB options:
location
: The location of the SQLite database file. Seeop-sqlite's docs for more details.encryptionKey
: The encryption key for SQLCipher. Seeop-sqlite's docs for more details.
You amy get the following error when new arch is enabled:
(NOBRIDGE) ERROR Error: Failed to install react-native-quick-crypto: React Native is not running on-device. QuickCrypto can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead. (NOBRIDGE) ERROR TypeError: Cannot read property 'install' of undefined
- This is a know issue:Error: Failed to install react-native-quick-crypto: React Native is not running on-device. · Issue #333 · margelo/react-native-quick-crypto · GitHub
For now, you have to edit:
lib/module/NativeQuickCrypto/NativeQuickCrypto.js
And comment them out:
// Check if we are running on-device (JSI) // if (global.nativeCallSyncHook == null || QuickCryptoModule.install == null) { // throw new Error('Failed to install react-native-quick-crypto: React Native is not running on-device. QuickCrypto can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'); // }
See thecontributing guide to learn how to contribute to the repository and the development workflow.
MIT © Takuya Matsuyama
About
PouchDB adapter using ReactNative SQLite as its backing store
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.