Ionic 2 包含的数据库
Ionic 2 Included Database
我一直在研究如何使用包含的 SQLStorage 插件来创建本地持久存储。我的目标是创建这样一个数据库,但将其包含在应用程序文件中,这样就不需要重新检索数据。我知道在设置数据库时有一个 existingDatabase 标志,但这似乎没有预期的行为。有没有办法将数据库的位置指定到 www 文件夹,或者类似的东西?
使用此处提供的数据库复制插件:https://github.com/an-rahulpandey/cordova-plugin-dbcopy
你的.db
应该在www
目录下,如果已经复制过的话。
window.plugins.sqlDB.copy("my.db", function() {
db = $cordovaSQLite.openDB("my.db"); //replace with your db name
}, function(error) {
console.error("There was an error copying the database: " + error);
db = $cordovaSQLite.openDB("my.db");
});
您需要调整以上代码以用于 ionic2 的 sql 存储。
我一直在研究如何使用包含的 SQLStorage 插件来创建本地持久存储。我的目标是创建这样一个数据库,但将其包含在应用程序文件中,这样就不需要重新检索数据。我知道在设置数据库时有一个 existingDatabase 标志,但这似乎没有预期的行为。有没有办法将数据库的位置指定到 www 文件夹,或者类似的东西?
使用此处提供的数据库复制插件:https://github.com/an-rahulpandey/cordova-plugin-dbcopy
你的.db
应该在www
目录下,如果已经复制过的话。
window.plugins.sqlDB.copy("my.db", function() {
db = $cordovaSQLite.openDB("my.db"); //replace with your db name
}, function(error) {
console.error("There was an error copying the database: " + error);
db = $cordovaSQLite.openDB("my.db");
});
您需要调整以上代码以用于 ionic2 的 sql 存储。