1
votes

I'm trying to use react-native-sqlite-storage to work with the local db on react native, for ios.

var SQLite = require('react-native-sqlite-storage');
var db = []; 

export default class DataBase {
  constructor () {
    db = SQLite.openDatabase("eventHelper.db", "1.0", "EventHelper", 200000, this.openCB, this.errorCB);
  }

  errorCB(err) {
    console.log("SQL Error: " + err);
  }

  successCB() {
    console.log("SQL executed fine");
  }

  openCB() {
    console.log("Database OPENED");
  }
}

But i get the following error message: Cannot read property 'open' of undefined. I don't know exactly how does openDatabase works, i have not created the database. I am not sure wether i should create the database first, and how, or if openDatabase is doing this if the database does not exist.

I looked for this problem, and i tried the solution suggested here https://github.com/andpor/react-native-sqlite-storage/issues/64 - uninstalled react-native-sqlite-storage - removed the node_modules folder - npm install - npm install --save react-native-sqlite-storage - rnpm link

but my build failsenter image description here

Any suggestion will be highly appreciated. Thanks!

2

2 Answers

2
votes

Did you re-run react-native run-ios after you installed the SQLite plugin? I got the same error and that fixed it, hope it helps

0
votes

A simple usage example ( currently I'm using it in a production app )

var SQLite = require('react-native-sqlite-storage');
var db = SQLite.openDatabase({name : "db.sqlite", location: 'default'});

db.executeSql("SELECT * FROM users WHERE userName=?",['user1'],
            (results) => {
              console.log(results);
            },
            (err) => {
              console.log(err);
            }
            );