Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230910

Can't get data from cordova sqlite

$
0
0

Alright. Two things.
So you almost never want to type function inside an Ionic app. Instead, you want to utilize the fat arrows syntax () =>.
Secondly, Promise nesting is an anti-pattern and should be avoided.

That being said, here’s what I’d suggest:

this.sqlite.create({
  name: 'data.db',
  location: 'default'
})
.then((db: SQLiteObject) => {
  console.log('SELECT * FROM message');
  return db.executeSql('SELECT * FROM message', {});
})
.then((data) => {
  for(let i = 0; i < data.rows.length; i++) {
    let id = data.rows.item(i).id;
    let message_to = data.rows.item(i).message_to;
    let message_text = data.rows.item(i).message_text;
    this.messages.push({
        id: id,
        message_to: message_to,
        message_text: message_text
    });
  }
})
.catch(e => console.log(e));

Viewing all articles
Browse latest Browse all 230910

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>