Natanael
Natanael

Reputation: 1346

SQLite not working on Ionic 2

Cannot use SQLite plugin in my Angular 2/Ionic 2 project.

The way SQLite is instantiated accordint to the Ionic 2 documentation is not working.

Sublime give me an error message:

Supplied parameters do not match nay signature of the call target.

It means that the constructor shoud receive parameters. But what parameters?

Ionic 2 SQLite plugin documentation: http://ionicframework.com/docs/v2/native/sqlite/

import { SQLite } from 'ionic-native';

let db = new SQLite();
db.openDatabse({
  name: 'data.db',
  location: 'default' // the location field is required
}).then(() => {
  db.executeSql('create table danceMoves(name VARCHAR(32))', {}).then(() => {

  }, (err) => {
    console.error('Unable to execute sql', err);
  })
}, (err) => {
  console.error('Unable to open database', err);
});

It also says Property 'openDatabse' does not exist on type 'SQLite'

Upvotes: 2

Views: 2734

Answers (4)

Manish
Manish

Reputation: 13557

I resolved this issue by following steps.

Add and install plugin

ionic cordova plugin add cordova-sqlite-storage

npm install --save @ionic-native/sqlite

Now create a database.

let db = new SQLite();
            db.openDatabase({
                name: "data.db",
                location: "default"
            }).then(() => {
});

If you getting an error like: "openDatabse does not exist on type 'SQLite". Just delete node_module folder and reinstall node_module.

It will work.

Upvotes: 0

Sameeksha Kumari
Sameeksha Kumari

Reputation: 1264

May be try to import SQLite object using

import { SQLite, SQLiteObject } from '@ionic-native/sqlite';

Note : Dont forget to install ionic-native/sqlite

npm install --save @ionic-native/sqlite

Upvotes: 1

Pétalomine
Pétalomine

Reputation: 1

It's db.openDatabase, not Databse

But I think that now it's .create and not .openDatabase.

When you say .then(() => {db.executeSql ... try to add .then((db: SQLiteObject) and for the next then : {}).then(() => {}, (err) => { add data between the ( )

Upvotes: -1

Natanael
Natanael

Reputation: 1346

Solved by recreating the project from scratch and coping old app folder, configs and reinstalling npm modules and ionic native plugins.

Upvotes: 1

Related Questions