Load pre populated SQLite database - impossible in Ionic 2

Hi,

I was just wondering if there is a way to load an exising SQL database on Ionic 2 project load?
As I noticed, there is an option in SqlStorage:

if (win.sqlitePlugin) {
var location_1 = this._getBackupLocation(dbOptions.backupFlag);
this._db = win.sqlitePlugin.openDatabase(util_1.assign({
name: dbOptions.name,
location: location_1,
createFromLocation: dbOptions.existingDatabase ? 1 : 0
}, dbOptions));
}

but in any case the code wont run as ‘win.sqlitePlugin’ equals ‘undefined’.

Any ideas?

Are you running in a browser or on a device? Cordova plugins don’t generally work in browser environments.

Thanks rapropos for reply. The test that I have done was in browser env. - I will check it on device then.
However do you know the best way of integrating an existing DB on app run?

I figure it’s dangerous to assume binary compatibility in all the different environments Ionic applications try to run in, so I just issue SQL to initialize databases.

So how to fill in the DB with the initial data - any advice how it should look like?

Since a week - no response. I jave tried several ways to integrate the data but with no result. Is there anyone who managed to load a pre filled database in Ionic 2? Thanks.

Maybe you can do it using SQL…what do you think?

Could you please give me more details regarding the code structure? Do you mean use an external db with Ionic 2 services?

Also question: why would you give up then with SQLite?

We’re suggesting populating the database with ordinary SQL INSERT statements.

This means that the solution is an external database.
My idea was to drop a ready database file avoiding any internet connexion.

Nobody said anything about internet connections. SQLite is an SQL engine. You can issue CREATE TABLE and INSERT statements to it just as you can any other SQL engine.

Ok but can you imagine the INSERT statement for 10 000 entries in the core of code - for me it’is dirty solution, or do you think maybe of json file as a source?