-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscore.js
49 lines (44 loc) · 1.8 KB
/
score.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
41
42
43
44
45
46
47
48
49
//用户打分
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('test.db');
var Promise = require('bluebird');
exports.setScore=(uid,fid,score)=>{
return new Promise(
(resolve,reject)=>{
db.all('select * from score where uid=? and fid=?',[uid,fid],function(err,res){
if(!err)
{
if(res.length==0)
{
db.run('INSERT INTO score(uid, fid,score) VALUES (?,?,?)',[uid,fid,score],function(err){
if(err)
{
console.log("err");
reject(err);
}
else
{
resolve(score);
}
});
}
else
{
db.run('UPDATE score SET score=? where uid=? and fid=?',[score,uid,fid],function(err){
if(err)
{
console.log("err");
reject(err);
}
else
{
resolve(score);
}
});
}
}
else
reject(err);
});
});
};