-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdao_images.js
44 lines (41 loc) · 1.34 KB
/
dao_images.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
class DAOImages {
/**
* Inicializa el DAO de las preguntas.
*
* @param {Pool} pool Pool de conexiones MySQL. Todas las operaciones
* sobre la BD se realizarán sobre este pool.
*/
constructor(pool) {
this.pool = pool;
}
getUserImages(user_id, callback) {
this.pool.getConnection((err, connection) => {
if (err) {
callback(err, undefined);
return;
}
connection.query("SELECT image, description FROM user_images WHERE user_id=?",[user_id],
function (err, images) {
connection.release();
if (err) { callback(err, undefined); return; }
else {
callback(err, images);
}
})
})
}
addImage(userId,img,text, callback) {
this.pool.getConnection((err, connection) => {
if (err) { callback(err); return; }
connection.query("INSERT INTO user_images (user_id, image,description)" +
" VALUES (?, ?, ?)", [userId, img, text],
(err)=> {
connection.release();
callback(err);
})
});
}
}
module.exports = {
DAOImages: DAOImages
}