-
Notifications
You must be signed in to change notification settings - Fork 0
/
groups.js
44 lines (36 loc) · 1.02 KB
/
groups.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
var q = require('q');
var mysql = require("mysql");
var pool = mysql.createPool({
host: "localhost",
port: 3306,
user: "root",
password: "",
database: "todo_list",
connectionLimit: 4
});
function Group(id, name, creator) {
this.id = id;
this.name = name;
this.creator_id = creator;
}
const SAVENEWGROUPSQL = "INSERT INTO groups (name, creator_id) VALUES (?,?)";
var makeQuery = function (sql, pool) {
return function (args) {
var defer = q.defer();
pool.getConnection(function (err, connection) {
if (err) {
return defer.reject(err);
}
connection.query(sql, args || [], function (err, result) {
connection.release();
if (err) {
return defer.reject(err);
}
defer.resolve(result);
})
});
return defer.promise;
};
};
Group.prototype.saveNewGroup = makeQuery(SAVENEWGROUPSQL, pool);
module.exports = Group;