0
私はIonicでSQLiteを使うことを学んでいます。私が従った例から、私はこのコードを思いついた。あなたがこの方法navigateToRegisterPage()
を見ればクエリを実行するたびにsqlite用のcreateを使用する
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');
})
})
}
}
私は、SELECTをしていますが、私はthis.sqlite.create
最初のをしています。クエリを実行するたびにそれを行う必要がありますか、それを行うための他の方法がありますか?