【发布时间】:2018-05-10 02:06:03
【问题描述】:
我正在学习在 Ionic 中使用 SQLite。从我遵循的示例中,我想出了这段代码。
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
@IonicPage()
@Component({
selector: 'page-sqlite',
templateUrl: 'sqlite.html',
})
export class SqlitePage {
constructor(public navCtrl: NavController, public navParams: NavParams, public sqlite: SQLite) {
this.sqlite.create({
name: 'data.db',
location: 'default'
})
.then((db: SQLiteObject) => {
db.executeSql('create table if not exists danceMoves(name VARCHAR(32))', {})
.then(() => console.log('Executed SQL'))
.catch(e => console.log(e));
})
.catch(e => console.log(e));
}
ionViewDidLoad() {
console.log('ionViewDidLoad SqlitePage');
}
navigateToRegisterPage(){
this.sqlite.create({
name: 'data.db',
location: 'default'
})
.then((db: SQLiteObject) => {
db.executeSql('SELECT * FROM danceMoves', [])
.then(res => {
console.log(res);
console.log('The SELECT has been succesfully executed');
})
})
}
}
如果您查看 navigateToRegisterPage() 方法,我正在执行 SELECT,但我首先执行的是 this.sqlite.create。每次我想执行查询时都必须这样做,还是有其他方法可以做到这一点?
【问题讨论】:
标签: sqlite typescript ionic-framework ionic3