Prepopulated SQLite Databases in Ionic 2

Hi, don’t know if you still need help but if you still need help i figured it out.

Basically you need to use the plugin cordova-sqlite-ext.

  1. To install use ionic plugin add cordova-sqlite-ext

  2. Copy your Database file to the /www folder

  3. In one of your classes (i tried it on MyApp class contructor after the platfor.ready(…) do this:
    this.storage = new Storage(SqlStorage,
    {
    name: ‘WUT.db’, <- Name of your database .db
    location: 1,<- Don’t know if this makes any difference
    backupFlag: SqlStorage.BACKUP_LOCAL,
    existingDatabase: true <-This way you’re looking for an existing DB
    });

  4. Now do something like
    storage.query(‘SELECT * from table’).then
    (
    (data) => { console.log(data): },
    (error) => { console.log(error); }
    });