var db;
function connectDb(dbPath, callback) {
db = new sqlite.Database(dbPath, function(err) {
if (typeof callback == "function")
callback(err);
})
}
//example:sql = "insert into student (name, age, sex) values (?, ?, ?)",obj = ["name", age, "sex"]
function addToDb(sql, obj, callback) {
db.run(sql, obj, function(err) {
callback(err);
})
}
// example:sql="delete from student where name = ?",opt=["id"](where后的=和==没有区别)
function delFromDb(sql, opt, callback) {
db.run(sql, opt, function(err) {
callback(err);
})
}
//example:sql = update student set name = ? where name = ?, obj = ["newname"],
function updateDb(sql, obj, callback) {
db.run(sql, obj, function(err) {
callback(err);
})
}
function selectSingalFromDb(sql, opt, callback) { //查询第一条信息
db.get(sql, opt, function(err, obj) {
callback(err, obj);
})
}
function connectDb(dbPath, callback) {
db = new sqlite.Database(dbPath, function(err) {
if (typeof callback == "function")
callback(err);
})
}
//example:sql = "insert into student (name, age, sex) values (?, ?, ?)",obj = ["name", age, "sex"]
function addToDb(sql, obj, callback) {
db.run(sql, obj, function(err) {
callback(err);
})
}
// example:sql="delete from student where name = ?",opt=["id"](where后的=和==没有区别)
function delFromDb(sql, opt, callback) {
db.run(sql, opt, function(err) {
callback(err);
})
}
//example:sql = update student set name = ? where name = ?, obj = ["newname"],
function updateDb(sql, obj, callback) {
db.run(sql, obj, function(err) {
callback(err);
})
}
function selectSingalFromDb(sql, opt, callback) { //查询第一条信息
db.get(sql, opt, function(err, obj) {
callback(err, obj);
})
}