Ionic 3 - insert SQLite with http -
i'm trying create small app using sqlite storing data. want fetch data through http request little bit in problem handle this.
here method data (trying json)
public dataarray: array<people>; loaddata() { return this.http.get('assets/data/peoples.json') .map(res => res.json()) } private insertdefaultitems(db: sqliteobject) { db.executesql('select count(id) qtd people', {}) .then((data: any) => { if (data.rows.item(0).qtd == 0) { this.loaddata().subscribe((res) => { this.dataarray = res.peoples }) for(var = 0; < this.dataarray.length; i++) { db.sqlbatch([ ['insert people (firstname, lastname, email) values (?,?,?)', [this.dataarray[i].firstname, this.dataarray[i].lastname, this.dataarray[i].email]], ]) .then(() => console.log('insert completed')) .catch(e => console.error('error insert')); } } }) .catch(e => console.error('error insert in table')); }
it works quite fine when want use didn't work - can do?
Comments
Post a Comment