1 var db
= require("../utils/database");
5 * id: problem number (int)
7 * vid: variant id (int)
14 exports
.create = function(vid
, fen
, instructions
, solution
)
16 db
.serialize(function() {
18 "INSERT INTO Problems (added, vid, fen, instructions, solution) VALUES " +
30 exports
.getOne = function(id
, callback
)
32 db
.serialize(function() {
37 db
.get(query
, callback
);
41 exports
.fetchN = function(vid
, uid
, type
, directionStr
, lastDt
, MaxNbProblems
, callback
)
43 db
.serialize(function() {
46 typeLine
= "AND id " + (type
=="others" ? "!=" : "=") + " " + uid
;
48 "SELECT * FROM Problems " +
49 "WHERE vid = " + vid
+
50 " AND added " + directionStr
+ " " + lastDt
+ " " + typeLine
+ " " +
51 "ORDER BY added " + (directionStr
=="<" ? "DESC " : "") +
52 "LIMIT " + MaxNbProblems
;
53 db
.all(query
, callback
);
57 exports
.update = function(id
, uid
, fen
, instructions
, solution
)
59 db
.serialize(function() {
62 "fen = " + fen
+ ", " +
63 "instructions = " + instructions
+ ", " +
64 "solution = " + solution
+ " " +
65 "WHERE id = " + id
+ " AND uid = " + uid
;
70 exports
.remove = function(id
, uid
)
72 db
.serialize(function() {
74 "DELETE FROM Problems " +
75 "WHERE id = " + id
+ " AND uid = " + uid
;