import { Injectable } from '@angular/core' ; import { SQLite , SQLiteObject } from '@ionic-native/sqlite' ; @ Injectable ( ) export class DBService { myDataBase : SQLiteObject ; constructor ( private sqlite ) { } initDB ( ) { this . sqlite . create ( { name : 'basic.db' , location : 'default' } ) . then ( ( database ) => { let sqlStr = ' create table if not exists contact ' + '(' + 'id INTEGER PRIMARY KEY autoincrement, ' + 'name text, ' + 'phone text, ' + 'index text, ' + ')' ; database . executeSql ( sqlStr , { } ) . then ( ( ) => { console . log ( '创建表成功' ) ; } ) . catch ( ( ) => { console . log ( '创建表失败' ) ; } ) ; this . myDataBase = database ; } ) . catch ( ( ) => { console . log ( '打开数据库失败' ) ; } ) ; } }