1、判断数据库是否打开
isOpen() {let open = plus.sqlite.isOpenDatabase({name: this.dbName,path: this.dbPath})return open;}
2、创建数据库(有就打开)
openSqlite() {return new Promise((resolve, reject) => {plus.sqlite.openDatabase({name: this.dbName,path: this.dbPath,success(e) {resolve(e); },fail(e) {reject(e);}})})}
3、关闭数据库
closeSqlite() {return new Promise((resolve, reject) => {plus.sqlite.closeDatabase({name: this.dbName,success(e) {resolve(e);},fail(e) {reject(e);}})})}
4、执行sql
createTable(dbTable, data) {return new Promise((resolve, reject) => {plus.sqlite.executeSql({name: this.dbName,sql: `CREATE TABLE IF NOT EXISTS ${dbTable}(${data})`,success(e) {resolve(e);},fail(e) {reject(e);}})})}