forked from net900621/thrush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbdemo.js
40 lines (39 loc) · 966 Bytes
/
dbdemo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//添加
function dbAdd (self, key, opt) {
var tableName = opt.tableName;
var keyName = opt.keyName;
var valueName = opt.valueName;
var content = {};
content[keyName] = valueName;
var callback = function(err, db, self, key){
var _self = self,
_key = key;
if (err) return console.error('Connection error: ' + err);
var MYTABLE = db.define(tableName, {
id : {type: 'serial', key: true},
name : {type: 'text'},
sex : {type: 'text'}
});
MYTABLE.create([
{
name: "John"
}
], function (err, items) {
// err - description of the error or null
// items - array of inserted items
});
}
doDb(self, key, callback);
}
//更新
Person.get(1, function (err, John) {
John.save({ name: "Joe", surname: "Doe" }, function (err) {
console.log("saved!");
});
});
//删除
Person.get(1, function (err, John) {
John.remove(function (err) {
console.log("removed!");
});
});