Reputation: 100
I'm new to ionic app development.
Going to develop a dictionary app with ionic, angular and sqlite.
SQLite db file is already prepared with required tables and the app needs to be deployed with the db file.
As the first step how can I read data from db file?
Should I use
SQLite https://ionicframework.com/docs/native/sqlite
or
SQLite Porter https://ionicframework.com/docs/native/sqlite-porter
let db = (<any>window).openDatabase('dictionary', '1.0', 'dictionary', 1 * 1024);
this.http.get('../assets/database/dictionary.db', { responseType: 'text' })
.subscribe(sql => {
this.sqlitePorter.importSqlToDb(db, 'select * from terms')
.then(() => console.log('Imported'))
.catch(e => console.error(e));
}, error => {
console.log('error: ' + JSON.stringify(error));
});
I tried above coding but it gives me 404 not found error on Android Studio emulator.
Upvotes: 0
Views: 1015
Reputation: 100
The import file should be .sql not .db. Since SqliteDbCopy is having an copying issue with capacitor, I used SQLitePorter
Final solution is to use capacitor, SQLitePorter and .sql file to import data.
Upvotes: 1