Can't resolve all parameters for SQLiteObject(?)


#1

i’m trying to perform ionic native sqlite operations.I have created a provider for all sqlite operations . In my view i have created a simple fields to collect some data. I have a dummy sql data too.

my database.ts

import { HttpClient } from ‘@angular/common/http’;
import { Injectable } from ‘@angular/core’;
import { Platform } from ‘ionic-angular’;
import { SQLite, SQLiteObject } from ‘@ionic-native/sqlite’;
import { SQLitePorter } from ‘@ionic-native/sqlite-porter’;
import { Http } from ‘@angular/http’;
import ‘rxjs/add/operator/map’;
import { BehaviorSubject } from ‘rxjs/Rx’;
import { Storage } from ‘@ionic/storage’;
/*
Generated class for the DatabaseProvider provider.

See https://angular.io/guide/dependency-injection for more info on providers
and Angular DI.
*/
@Injectable()
export class DatabaseProvider {
database : SQLiteObject;
private databaseReady : BehaviorSubject;

constructor( public sqliteporter: SQLitePorter,private storage: Storage,private sqlite: SQLite,private platform: Platform, public http: HttpClient) {
this.databaseReady = new BehaviorSubject(false);
this.platform.ready().then(() => {
this.sqlite.create({
name: ‘developer.db’,
location: ‘default’
})
.then((db: SQLiteObject) => {
this.database = db;
this.storage.get(‘database_filled’).then(val => {
if(val) {
this.databaseReady.next(true);
} else {
this.fillDatabase();
}
});
});
});
}

addDeveloper(name,skill,years ) {
let data = [name,skill,years]
return this.database.executeSql(“INSERT INTO developer (name, skill, yearsOfExperience) VALUES (?, ?, ?)”,data).then(data => {
return data;
}, err => {
console.log(‘Error:’, err);
return err;
});
}

getAllDevelopers() {
return this.database.executeSql(“SELECT * FROM developer”,[]).then((data) => {
let developers = [];
if(data.rows.length > 0 ) {
for ( var i = 0; i< data.rows.length;i++ ) {
developers.push({name: data.rows.item(i).name, skill: data.rows.item(i).skill, yearsOfExperience: data.rows.item(i).yearsOfExperience });

    }
  }
  return developers;
}, err => {
  console.log("Error:",err);
  return[];
});

}

fillDatabase() {
this.http.get(‘assets/dummyDump.sql’)
.map(res => res.toString())
.subscribe(sql => {
this.sqliteporter.importSqlToDb(this.database,sql)
.then(data => {
this.databaseReady.next(true);
this.storage.set(‘database_filled’,true);
})
.catch(e => console.error(e));
});
}
getDatabaseState() {
return this.databaseReady.asObservable();
}

}

my home.html

Developer data Name What's your special skill? How long have you been working? Add Developer Info

{{ dev.name }}

{{ dev.yearsOfExperience }} years of {{ dev.skill }} Experience!

my home.ts

import { DatabaseProvider } from ‘…/…/providers/database/database’;
import { Component } from ‘@angular/core’;
import { NavController,Platform } from ‘ionic-angular’;
import { SQLite,SQLiteObject } from ‘@ionic-native/sqlite’;
@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {

developer = {};
developers = [];

constructor(public navCtrl: NavController,private databaseprovider : DatabaseProvider ) {
this.databaseprovider.getDatabaseState().subscribe(rdy => {
if(rdy ) {
this.loadDeveloperData();
}
})
}

loadDeveloperData() {
this.databaseprovider.getAllDevelopers().then(data => {
this.developers = data;
})
}

addDeveloper() {
this.databaseprovider.addDeveloper(this.developer[‘name’],this.developer[‘skill’],parseInt(this.developer[‘yearsOfExperience’]))
.then(data => {
this.loadDeveloperData();
});
this.developer = {};

}

}

after all these it’s giving me error like this

Uncaught Error: Can’t resolve all parameters for SQLiteObject: (?).


#2

A quick look at the docs suggests that you shouldn’t have SqLiteObject declared as a property. So database: SqLiteObject; looks like the cause.

Remove it from your class declarations


#3

following your answer @jaydz i have changed database: SQLiteObject to database: any but it’s again returning me a blank screen