Git Product home page Git Product logo

pouchdb-adapter-react-native-sqlite's Introduction

pouchdb-adapter-react-native-sqlite

PouchDB adapter using ReactNative SQLite as its backing store.

Why?

SQLite storage performs much faster than AsyncStorage, especially with secondary index. Here is benchmark results:

1) allDocs speed min max mean
AsyncStorage 72ms 94ms 77ms
SQLite 27ms 39ms 28ms
2) query speed min max mean
AsyncStorage 1,075ms 1,117ms 1,092ms
SQLite 33ms 39ms 35ms
  • Device: iPhone 6s
  • Documents: 434
  • Update seq: 453
  • Iterations: 100
  • Used options: { include_docs: true }

On Simulator

  • Device: iPad Pro 9.7" (Simulator) - iOS 10.3.2
  • Documents: 5000
3) bulkDocs speed total mean
AsyncStorage 25.821ms 5.16ms
SQLite 22.213ms 4.44ms
4) allDocs speed total mean
AsyncStorage 189,379ms 37.87ms
SQLite 30,527ms 6.10ms
  • allDocs options: { include_docs: true, attachments: true }
  • Using this test script

How to use it

Check out the craftzdog/pouchdb-react-native repository.

Changelog

  • 3.0.1
    • Fix dependency and import
  • 3.0.0
  • 2.0.0
    • Upgrade pouchdb-adapter-websql-core to 7.0.0
  • 1.0.3
    • Remove pouchdb-utils dependency
  • 1.0.2
    • Upgrade pouchdb-util & pouchdb-adapter-websql-core to 6.2.0
    • Update benchmark result
  • 1.0.1
    • Remove unnecessary console output
  • 1.0.0
    • Initial release

pouchdb-adapter-react-native-sqlite's People

Contributors

craftzdog avatar dependabot[bot] avatar hnq90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pouchdb-adapter-react-native-sqlite's Issues

PouchDB and SQLite not working on iOS

Hi @craftzdog,

I have issue with PouchDb react native sqlite adapter when using it on iOS device. I'm developing small React Native application for my SmartHome and using PouchDB to save some data locally on the phone.

The code works good when executing it on the Android device, but on the iOS device I get the following error:

WebSQL threw an error, [TypeError: sqlite.openDatabase is not a function. (In 'sqlite.openDatabase(openOpts.name, openOpts.version, openOpts.description, openOpts.size, null, onError)', 'sqlite.openDatabase' is undefined)]
- node_modules/expo/build/environment/muteWarnings.fx.js:26:24 in error
- node_modules/@sentry/utils/dist/instrument.js:104:50 in <unknown>
- node_modules/pouchdb-adapter-websql-core/node_modules/pouchdb-utils/lib/index-browser.js:457:26 in guardedConsole
- node_modules/pouchdb-adapter-websql-core/lib/index.js:239:32 in <unknown>
- node_modules/pouchdb-adapter-react-native-sqlite/lib/index.js:35:23 in ReactNativeSQLitePouch
- node_modules/pouchdb-react-native/node_modules/pouchdb-core/lib/index.js:1274:38 in PouchDB

I'm using expo project together with "expo-sqlite": "^8.0.0".

const SQLiteAdapter = SQLiteAdapterFactory(SQLite)
PouchDB.plugin(SQLiteAdapter)
PouchDB.plugin(require('pouchdb-find'));
PouchDB.plugin(require('pouchdb-upsert'));
return new PouchDB(dbName, {adapter: 'react-native-sqlite', revs_limit: 1, auto_compaction: true});

When I console log the last line or new PouchDB(...) object here is what I get:

PouchDB {
  "__opts": Object {
    "adapter": "react-native-sqlite",
    "auto_compaction": true,
    "name": "afa31ab81267925e8bd75233177a5988.db",
    "revs_limit": 1,
  },
  "_adapter": "react-native-sqlite",
  "_events": Object {},
  "_maxListeners": undefined,
  "_name": "afa31ab81267925e8bd75233177a5988.db",
  "adapter": "react-native-sqlite",
  "auto_compaction": true,
  "name": "afa31ab81267925e8bd75233177a5988.db",
  "prefix": "_pouch_",
  "taskqueue": TaskQueue$1 {
    "failed": [web_sql_went_bad: unknown],
    "isReady": false,
    "queue": Array [],
  },
}

Any idea what might be the problem?

Use LevelDB instead of SQLite

Hi.
I saw a bunch of packages for running PouchDB on React Native using SQLite.

This is what I´m proposing:

What if we transition everything into one repo, using LevelDB?

Error: extend is not a function

Hey!

First of all, thank you for this package. We've been updating it recently to 1.0.2 which is supposed to work with PouchDB version 6.2.0. However, I experienced this error :
screenshot from 2017-06-12 14-10-54
This is an importing issue, I managed to solve it by replacing var extend = PouchUtils.jsExtend with var extend = require('pouchdb-extend') in pouchdb-adapter-react-native-sqlite/lib/index.js and running npm install pouchdb-extend. Obviously, this is not suitable for long-term, could you check if the mentioned versions above are working correctly together?
Thank you!

Undefined is not an object (evaluating 'RNSqlite2.exec')

Hi,

I have the following code but when app starts, an error is thrown.

undefined is not an object (evaluating 'RNSqlite2.exec')
exec
    ..\node_modules\react-native-sqlite-2\src\SQLiteDatabase.js:74:12
runBatch
    ..\node_modules\websql\lib\websql\WebSQLTransaction.js:54:32
runAllSql
    ..\node_modules\websql\lib\websql\WebSQLTransaction.js:96:11
_checkDone
    ..\node_modules\websql\lib\websql\WebSQLTransaction.js:133:12
<unknown>
    ..\node_modules\websql\lib\websql\WebSQLDatabase.js:62:4
run
    ..\node_modules\websql\node_modules\immediate\lib\index.js:71:11
nextTick
    ..\node_modules\websql\node_modules\immediate\lib\index.js:42:6
<unknown>
    ..\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:297:23
_callTimer
    ..\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:154:6
_callImmediatesPass
    ..\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:202:17
callImmediates
    ..\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:466:11
__callImmediates
    ..\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:329:4
<unknown>
    ..\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:147:6
__guardSafe
    ..\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:316:6
flushedQueue
    ..\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:146:17
callFunctionReturnFlushedQueue
    ..\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:121:11```


import PouchDB from "pouchdb-react-native";
import SQLite from "react-native-sqlite-2";
import SQLiteAdapterFactory from "pouchdb-adapter-react-native-sqlite";

const SQLiteAdapter = SQLiteAdapterFactory(SQLite);
PouchDB.plugin(SQLiteAdapter);

const localDB = new PouchDB("mydb.db", { adapter: "react-native-sqlite" });

Dependencies

 "pouchdb-adapter-react-native-sqlite": "^1.0.3",
    "pouchdb-find": "^6.4.3",
    "pouchdb-react-native": "^6.4.0",
    "react": "16.3.0-alpha.1",
    "react-native": "^0.54.2",
    "react-native-action-button": "^2.8.4",
    "react-native-deprecated-custom-components": "^0.1.2",
    "react-native-sqlite-2": "^1.5.2",
    "react-navigation": "^1.5.8"

If I change the line

const localDB = new PouchDB("mydb.db", { adapter: "react-native-sqlite" });

to

const localDB = new PouchDB("myDB");

It works.

Any ideas what could be the issue.

Thank you

Working Demo App doesn't work

Cloned the app couldn't run it.

npm install
npx react-native run-ios

get error:

The following commands produced analyzer issues:
	Analyze /Users/*****/Documents/pouchdb-react-native-demo/node_modules/react-native/ReactCommon/jsi/jsi.cpp normal x86_64
	Analyze /Users/*****/Documents/pouchdb-react-native-demo/node_modules/react-native/ReactCommon/yoga/yoga/Yoga.cpp normal x86_64
	Analyze /Users/*****/Documents/pouchdb-react-native-demo/node_modules/react-native/React/Base/RCTModuleMethod.mm normal x86_64
(3 commands with analyzer issues)

The following build commands failed:
	Ld /Users/*****/Documents/pouchdb-react-native-demo/ios/build/Sqlite3Demo/Build/Products/Debug-iphonesimulator/Sqlite3Demo.app/Sqlite3Demo normal
(1 failure)

using xcode 12.3
simulator: iPhone 11 running iOS 14..3

EDIT:

In fact

npm install

doesn't even work

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

The issue is that the websql dependency has a dependency on sqlite3 4.X which is not compatible with node v14.

The fix is to manually install Sqlite3 5.X or greater for those with this issue

e.g

npm install sqlite3@latest

pouchdb allDocs with specific keys return all documents in Database

First, thanks for your great adapter and SQLite library for React Native, it save a lots day of us when implement CouchDb in mobile.

But, from PouchDb 6.4 when use allDocs API with keys option always return all documents in Database.

I think it relation with some change in allDocs API of PouchDB: https://github.com/pouchdb/pouchdb/releases/tag/6.4.0

And react-native-sql2 had incompatable with new change.

Because react-native-sql2 not have direct relation with React Native, so i post this issue here.

Similiar Issue here: pouchdb/pouchdb#7007

Hope to receive your respond soon

Doesnt support RN 0.61.5?

Does this library supports RN 0.61.5?
I am getting following errors while running react-native run-android:

`> Task :app:processDebugManifest FAILED

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

22 actionable tasks: 10 executed, 12 up-to-date
pouchdb-react-native-demo-new\android\app\src\debug\AndroidManifest.xml:22:18-91 Error:
Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.1] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:7:5-138 to override.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.1] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:7:5-138 to override.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 3s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
pouchdb-react-native-demo-new\android\app\src\debug\AndroidManifest.xml:22:18-91 Error:
Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.1] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:7:5-138 to override.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.0.1] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:7:5-138 to override.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 3s
at checkExecSyncError (child_process.js:629:11)
at execFileSync (child_process.js:647:13)
at runOnAllDevices (pouchdb-react-native-demo-new\node_modules@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
at process._tickCallback (internal/process/next_tick.js:68:7)
`

Thanks!

Hey just wanted to say thank you for this! I'm just getting started on a project and already ran into issues with pouchdb-react-native.

Any gotchas I should look out for?

CDB replication + local query is broken

I step in your pouchdb adapter in hope to find working solution for bundle of pouchdb on RN + couchdb backend.
But it seems that sqlite is broken in the same manner as asyncstorage is, details are here
Both - mapreduce and find plugins show exactly same behaviour: after changed docs replication from CDB query starts to show only last updated on server doc, nevertheless all other docs remain untouched in local PDB.
My first question:
is there any chance that this bug will be resolved in a some visible future?

PDBRN seems unmantained (at least since August), but the only unique thing there is asyncstorage adapter, the rest could be combined of recent pouchdb-core + plugins.

But your adapter depends on PDBRN, so my second question:
is there any way to use sqlite adapter in counjunction with pure PDB, without need of PDBRN?

Get performance degrades 10x

I'm new to PouchDB / CouchDB. Very excited to find your package on account of the performance gains. Alas, I'm seeing performance problems. I guess it's something on my side, but I'm not sure how to investigate / debug. Any input would be greatly appreciated.

I have 3 PouchDB databases which are doing one way replication from a cloudant instance. The databases are ~8k records 22MB, ~150 records 210k, ~3.5k records 5MB. The data is synced very quickly into my local PouchDB databases.

I can .allDocs() on the ~150 record database in ~200ms. Performance is great.

I'm trying to fetch ~350 documents from the database with 8k records. If I use .allDocs({keys: [...]}) it takes >40s to load the data. If I iterate with a Promise.each([...]) (from bluebird) to fetch each record serially via .get(id), each fetch can take up to 3s or more.

If I disable { adapter: "react-native-sqlite" } line, then performance is significantly better in the iOS simulator. The ~350 documents load in ~4s (via the serial fetch method).

Any advice on how I can debug this issue?

TypeError: Cannot read property 'exec' of undefined

This is my code but I got the error TypeError: Cannot read property 'exec' of undefined. Any idea?

import PouchDB from 'pouchdb-react-native'
import SQLite from 'react-native-sqlite-2'
import SQLiteAdapterFactory from 'pouchdb-adapter-react-native-sqlite'

const SQLiteAdapter = SQLiteAdapterFactory(SQLite)
PouchDB.plugin(SQLiteAdapter)
const db = new PouchDB('mydb.db', {adapter: 'react-native-sqlite'});
db.get('4711')
  .then(doc => console.log(doc))

Full Error:

/home/chris/Projects/tailpos-mobile/node_modules/react-native-sqlite-2/src/SQLiteDatabase.js:74
RNSqlite2.exec(
          ^

TypeError: Cannot read property 'exec' of undefined
    at SQLiteDatabase.exec (/home/chris/Projects/tailpos-mobile/node_modules/react-native-sqlite-2/src/SQLiteDatabase.js:74:11)
    at runBatch (/home/chris/Projects/tailpos-mobile/node_modules/websql/lib/websql/WebSQLTransaction.js:54:28)
    at runAllSql (/home/chris/Projects/tailpos-mobile/node_modules/websql/lib/websql/WebSQLTransaction.js:96:3)
    at WebSQLTransaction.Object.<anonymous>.WebSQLTransaction._checkDone (/home/chris/Projects/tailpos-mobile/node_modules/websql/lib/websql/WebSQLTransaction.js:133:3)
    at /home/chris/Projects/tailpos-mobile/node_modules/websql/lib/websql/WebSQLDatabase.js:62:9
    at Item.Object.<anonymous>.Item.run (/home/chris/Projects/tailpos-mobile/node_modules/websql/node_modules/immediate/lib/index.js:71:12)
    at nextTick (/home/chris/Projects/tailpos-mobile/node_modules/websql/node_modules/immediate/lib/index.js:42:32)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
error Command failed with exit code 1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.