Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/craftzdog/pouchdb-adapter-react-native-sqlite
PouchDB adapter using ReactNative SQLite as its backing store
https://github.com/craftzdog/pouchdb-adapter-react-native-sqlite
database pouchdb react-native sqlite3
Last synced: 5 days ago
JSON representation
PouchDB adapter using ReactNative SQLite as its backing store
- Host: GitHub
- URL: https://github.com/craftzdog/pouchdb-adapter-react-native-sqlite
- Owner: craftzdog
- License: mit
- Created: 2016-12-20T14:00:17.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-17T18:54:52.000Z (almost 2 years ago)
- Last Synced: 2024-04-22T01:55:31.523Z (9 months ago)
- Topics: database, pouchdb, react-native, sqlite3
- Language: JavaScript
- Homepage: https://github.com/craftzdog/pouchdb-react-native
- Size: 157 KB
- Stars: 116
- Watchers: 3
- Forks: 20
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-react-native - pouchdb-adapter-react-native-sqlite ★49 - PouchDB adapter using ReactNative SQLite as its backing store (Components / Storage)
README
# pouchdb-adapter-react-native-sqlite
PouchDB adapter using [op-sqlite](https://github.com/OP-Engineering/op-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.## How to use
### Installation
```sh
yarn add @op-engineering/op-sqlite react-native-quick-crypto @craftzdog/react-native-buffer
```### Polyfill NodeJS APIs
Create a `shim.ts` file like so:
```ts
import { install } from 'react-native-quick-crypto'install()
```Configure babel to use the shim modules. First, you need to install `babel-plugin-module-resolver`.
```sh
yarn add --dev babel-plugin-module-resolver
```Then, in your `babel.config.js`, add the plugin to swap the `crypto`, `stream` and `buffer` dependencies:
```js
plugins: [
[
'module-resolver',
{
extensions: ['.tsx', '.ts', '.js', '.json'],
alias: {
crypto: 'react-native-quick-crypto',
stream: 'readable-stream',
buffer: '@craftzdog/react-native-buffer',
},
},
],
],
```Then restart your bundler using `yarn start --reset-cache`.
### Install PouchDB and adapter
Now it's ready to use PouchDB!
```sh
yarn add pouchdb-core pouchdb-mapreduce pouchdb-replication pouchdb-adapter-http pouchdb-adapter-react-native-sqlite
```Create `pouchdb.ts`:
```ts
import PouchDB from 'pouchdb-core'
import HttpPouch from 'pouchdb-adapter-http'
import replication from 'pouchdb-replication'
import mapreduce from 'pouchdb-mapreduce'
import sqliteAdapter from 'pouchdb-adapter-react-native-sqlite'export default PouchDB.plugin(HttpPouch)
.plugin(replication)
.plugin(mapreduce)
.plugin(sqliteAdapter)
```### How to use PouchDB
```ts
import PouchDB from './pouchdb'const pouch = new PouchDB('mydb', {
adapter: 'react-native-sqlite',
})
```## Troubleshootings
### Fails to install crypto shim with `install()` on launch
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](https://github.com/margelo/react-native-quick-crypto/issues/333)
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.');
// }
```## Contributing
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
## License
MIT © Takuya Matsuyama