app-xiangsonghua/app-saas-src/script/dao/baseDao.js
2024-12-26 17:00:06 +08:00

55 lines
1.2 KiB
JavaScript

var baseDao = {}
baseDao.open = function(callback) {
var db = api.require("db");
var _this = this;
db.openDatabase({
name: _this.db
}, function(ret, err) {
if (!err && ret.status) {
if (typeof(callback) == "function") {
callback(db);
}
}
})
}
//查询
baseDao.query = function(sql, callback) {
var _this = this;
_this.open(function(db) {
db.selectSql({
name: _this.db,
sql: sql
}, function(ret, err) {
if (typeof(callback) == "function") {
callback(ret, err);
// console.log(sql);
// console.log("查到的数据");
// console.log(JSON.stringify(ret));
}
})
})
}
//执行
baseDao.exec = function(sql, callback) {
var userId = $api.getStorage("userId");
var _this = this;
_this.open(function(db) {
db.executeSql({
name: _this.db,
sql: sql
}, function(ret, err) {
// console.log(sql);
// console.log("执行结果");
// console.log(JSON.stringify(err));
if (typeof(callback) == "function") {
callback(ret, err);
}
})
})
}