-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
39 lines (33 loc) · 868 Bytes
/
db.js
File metadata and controls
39 lines (33 loc) · 868 Bytes
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
var sqlite3 = require('sqlite3');
var DB_NAME = 'robo-ops.db';
function DB() {
this.db = new sqlite3.Database(DB_NAME);
}
DB.prototype.getRocks = function(cb) {
this.db.all('SELECT * from rocks', function selectRocks(e, data) {
if (e) return cb(e);
cb(null, data);
});
};
DB.prototype.addRock = function(data, cb) {
var cmd = 'INSERT into rocks ' +
'(id, lon, lat, color) ' +
'VALUES (' +
'\'' + data.id + '\', ' +
' ' + data.lon + ', ' +
' ' + data.lat + ', ' +
'\'' + data.color + '\'' +
')';
this.db.run(cmd, function insertRock(e) {
if (e) return cb(e);
cb(null);
});
};
DB.prototype.removeRock = function(id, cb) {
var cmd = 'DELETE from rocks WHERE id = \'' + id + '\'';
this.db.run(cmd, function deleteRock(e) {
if (e) return cb(e);
cb(null);
});
};
module.exports = DB;