Pre-filled database in ionic 2

I have some static data and I created a SQLite database file using the DB Browser for SQLite . Now I want to use this SQLite database file in my Ionic 2 application.

I looked at https://forum.ionicframework.com/t/read-existing-sqlite-database-file-and-load-data/94167/10 , but did not get a solution.

Can anybody help me!

Ion Information:

@ionic/cli-utils : 1.9.2 ionic (Ionic CLI) : 3.9.2 

Global packages:

 Cordova CLI : 7.0.1 

Local packages:

 @ionic/app-scripts : 2.0.2 Cordova Platforms : none Ionic Framework : ionic-angular 3.5.3 
+5
source share
1 answer

You can achieve this using

cordova-sqlite-ext

for installation,

cordova plugin add cordova-sqlite-ext --save

Cordova / PhoneGap plugin for opening and using sqlite databases on Android / iOS / Windows with REGEXP (Android / iOS) and pre-populated databases (Android / iOS / Windows)

 var db = null; document.addEventListener('deviceready', function() { db = window.sqlitePlugin.openDatabase({name: 'demo.db', location: 'default'}); }); 

IMPORTANT Like other Cordoba plugins, the application must wait for deviceready events. This is especially difficult in Angular / ngCordova / Ionic controller / factory / service callbacks that can fire before the deviceready event fires.

Here is a detailed example of this.

Ionic Framework application with pre-populated SQLite DB

+1
source

Source: https://habr.com/ru/post/1271176/


All Articles