1. 安装SQLite的Cordova和Ionic Native插件:
$ ionic cordova plugin add cordova-sqlite-storage
$ npm install --save @ionic-native/sqlite
2.在app.module.ts中将SQLite导入装饰器,如下:
import { SQLite } from '@ionic-native/sqlite';
providers: [
...
SQLite,
...
]
3.封装服务类:SQLiteService.ts
3.1 初始化数据库:

3.2 封装执行sql操作方法:

4.封装dao服务类:
4.1 首先引入SQLiteService服务类:
import { SQLiteService } from '../common/SQLiteService';

4.2 定义使用的DDL、DML 如下:




5. 在使用场景中调用dao方法:
5.1 首先引入dao服务类:
import { personalInformationTable } from '../../dao/personalInformationTable';


5.2 实际调用dao的各个方法:

在调用dao服务类的方法时,应当特别注意this的指向问题。

网友评论