1 var db
= require("../utils/database");
5 * id: problem number (int)
7 * vid: variant id (int)
14 exports
.create = function(vname
, fen
, instructions
, solution
)
16 db
.serialize(function() {
20 "WHERE name = '" + vname
+ "'";
21 db
.get(vidQuery
, (err
,variant
) => {
23 "INSERT INTO Problems (added, vid, fen, instructions, solution) VALUES " +
36 exports
.getById = function(id
, callback
)
38 db
.serialize(function() {
40 "SELECT * FROM Problems " +
41 "WHERE id ='" + id
+ "'";
42 db
.get(query
, callback
);
46 exports
.getOne = function(vname
, pid
, callback
)
48 db
.serialize(function() {
53 db
.get(query
, callback
);
57 exports
.fetchN = function(vname
, uid
, type
, directionStr
, lastDt
, MaxNbProblems
, callback
)
59 db
.serialize(function() {
62 typeLine
= "AND id " + (type
=="others" ? "!=" : "=") + " " + uid
;
64 "SELECT * FROM Problems " +
65 "WHERE vid = (SELECT id FROM Variants WHERE name = '" + vname
+ "') " +
66 " AND added " + directionStr
+ " " + lastDt
+ " " + typeLine
+ " " +
67 "ORDER BY added " + (directionStr
=="<" ? "DESC " : "") +
68 "LIMIT " + MaxNbProblems
,
69 db
.all(query
, callback
);
73 exports
.update = function(id
, uid
, fen
, instructions
, solution
)
75 db
.serialize(function() {
78 "fen = " + fen
+ ", " +
79 "instructions = " + instructions
+ ", " +
80 "solution = " + solution
+ " " +
81 "WHERE id = " + id
+ " AND uid = " + uid
;
86 exports
.remove = function(id
, uid
)
88 db
.serialize(function() {
90 "DELETE FROM Problems " +
91 "WHERE id = " + id
+ " AND uid = " + uid
;