sqlite数据库连接

part1

  1. /****************第一步 命令行安装*******************/
  2. //在命令行中进入项目目录 输入下面进行安装
  3. ionic cordova plugin add cordova-sqlite-storage
  4. npm install --save @ionic-native/sqlite
  5. /****************第二步 加入到代码中*******************/
  6. //在 ./src/app/app.module.ts 中添加
  7. import {SQLite} from "@ionic-native/sqlite";
  8. //在 provides 中添加
  9. SQLite,
  10. /****************第三步 模块中*******************/
  11. //在要使用的模块中添加
  12. import {SQLite,SQLiteObject} from "@ionic-native/sqlite";
  13. //在constructor中加入
  14. private sqlite: SQLite
  15. //在代码中使用
  16. this.sqlite......

part2

/*************链接sqlite数据库***************/
this.sqlite.create({name: 'cheshiname.db',location: 'default'}).then(
(db: SQLiteObject) => {
this.myAppDatabase = db;
}
).catch(
e =>this.dd='写入数据库失败2'
);
/*************分析***************/
name ---- 数据库名称
location ---- 链接地址
then() ---- 链接成功返回值
catch() ---- 链接失败返回值
db ---- 链接对象

猜你喜欢

转载自www.cnblogs.com/fnms/p/9051722.html