简体   繁体   English

离子2中预先填充的数据库

[英]Pre-populated database in ionic 2

I have some static data and I have created a SQLite database file using DB Browser for SQLite for same. 我有一些静态数据,我使用DB浏览器为SQLite创建了一个SQLite数据库文件。 Now want use that SQLite database file in my Ionic 2 application. 现在想在我的Ionic 2应用程序中使用那个SQLite数据库文件。

I looked into https://forum.ionicframework.com/t/read-existing-sqlite-database-file-and-load-data/94167/10 post but didn't get a solution. 我查看了https://forum.ionicframework.com/t/read-existing-sqlite-database-file-and-load-data/94167/10帖子,但没有得到解决方案。

Can anyone please help me!!! 谁能帮帮我吗!!!

Ionic info: 离子信息:

@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

You can achieve this using 你可以使用这个来实现

cordova-sqlite-ext 科尔多瓦-sqlite的-EXT

for install, 安装,

cordova plugin add cordova-sqlite-ext --save

A Cordova/PhoneGap plugin to open and use sqlite databases on Android/iOS/Windows with REGEXP (Android/iOS) and pre-populated databases (Android/iOS/Windows) 用于在Android / iOS / Windows上使用REGEXP(Android / iOS)和预先填充的数据库(Android / iOS / Windows)打开和使用sqlite数据库的Cordova / PhoneGap插件

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

IMPORTANT : Like with the other Cordova plugins your application must wait for the deviceready event. 重要信息 :与其他Cordova插件一样,您的应用程序必须等待deviceready事件。 This is especially tricky in Angular/ngCordova/Ionic controller/factory/service callbacks which may be triggered before the deviceready event is fired. 这在Angular / ngCordova / Ionic控制器/工厂/服务回调中尤其棘手,这些回调可能在触发deviceready事件之前触发。

Here's detailed example for this. 这是详细的例子。

Ionic Framework App With Pre-Filled SQLite DB 具有预填充SQLite DB的离子框架应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM