1 var db
= require("../utils/database");
5 * _id: problem number (int)
7 * vid: variant id (int)
13 exports
.create = function(vname
, fen
, instructions
, solution
)
15 db
.serialize(function() {
16 db
.get("SELECT id FROM Variants WHERE name = '" + vname
+ "'", (err
,variant
) => {
18 "INSERT INTO Problems (added, vid, fen, instructions, solution) VALUES " +
30 exports
.getById = function(id
, callback
)
32 db
.serialize(function() {
34 "SELECT * FROM Problems " +
35 "WHERE id ='" + id
+ "'",
40 exports
.fetchN = function(vname
, directionStr
, lastDt
, MaxNbProblems
, callback
)
42 db
.serialize(function() {
44 "SELECT * FROM Problems " +
45 "WHERE vid = (SELECT id FROM Variants WHERE name = '" + vname
+ "') " +
46 " AND added " + directionStr
+ " " + lastDt
+ " " +
47 "ORDER BY added " + (directionStr
=="<" ? "DESC " : "") +
48 "LIMIT " + MaxNbProblems
,
53 exports
.update = function(id
, uid
, fen
, instructions
, solution
)
55 db
.serialize(function() {
58 "fen = " + fen
+ ", " +
59 "instructions = " + instructions
+ ", " +
60 "solution = " + solution
+ " " +
61 "WHERE id = " + id
+ " AND uid = " + uid
);
65 exports
.remove = function(id
, uid
)
67 db
.serialize(function() {
69 "DELETE FROM Problems " +
70 "WHERE id = " + id
+ " AND uid = " + uid
);