craftzdog / pouchdb-adapter-react-native-sqlite

PouchDB adapter using ReactNative SQLite as its backing store

Home Page:https://github.com/craftzdog/pouchdb-react-native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Cannot read property 'exec' of undefined

ccfiel opened this issue · comments

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.

It seems that SQLite module is not loaded correctly.
Set up react-native-sqlite-2 right way by following the instruction.

@craftzdog I check everything I followed the instruction. I am testing it using jest. Any Ideas? :)

You can not run any native modules on jest. Because it doesn't provide iOS/Android environment.

I see. Thanks!