通过ionic和angular从现有SQLite数据库读取数据



我是ionic应用程序开发的新手。
用ionic、angular和sqlite开发一个字典应用。
SQLite数据库文件已经准备好了所需的表,应用程序需要部署db文件。

作为第一步,我如何从db文件读取数据?

我应该使用SQLitehttps://ionicframework.com/docs/native/sqlite
SQLite Porterhttps://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));
});

我尝试了上面的编码,但它给了我404未发现错误在Android Studio模拟器。

导入文件应该是。sql而不是。db。由于SqliteDbCopy与电容有复制问题,我使用SQLitePorter

最后的解决方案是使用capacitor, SQLitePorter和.sql文件导入数据。

最新更新