craftzdog / pouchdb-adapter-react-native-sqlite

PouchDB adapter using ReactNative SQLite as its backing store
https://github.com/craftzdog/pouchdb-react-native
MIT License
130 stars 23 forks source link

TypeError: Cannot read property 'exec' of undefined #6

Closed ccfiel closed 6 years ago

ccfiel commented 6 years ago

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.
craftzdog commented 6 years ago

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

ccfiel commented 6 years ago

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

craftzdog commented 6 years ago

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

ccfiel commented 6 years ago

I see. Thanks!