-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_repository.js
60 lines (52 loc) · 1.13 KB
/
command_repository.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class CommandRepository {
constructor(dao) {
this.dao = dao
}
createTable() {
const sql = `
CREATE TABLE IF NOT EXISTS commands (
name TEXT PRIMARY KEY,
value TEXT,
periodic INTEGER)`
return this.dao.run(sql);
}
create(name, value) {
return this.dao.run(
`INSERT INTO commands (name, value, periodic)
VALUES (?, ?, ?)`,
[name, value, 0]);
}
createPeriodic(name, value) {
return this.dao.run(
`INSERT INTO commands (name, value, periodic)
VALUES (?, ?, ?)`,
[name, value, 1]);
}
update(command) {
console.log(command);
let name = command.commandName;
let value = command.commandValue;
return this.dao.run(
`UPDATE commands
SET value = ?
WHERE name = ?`,
[value, name]
);
}
delete(name) {
return this.dao.run(
`DELETE FROM commands WHERE name = ?`,
[name]
);
}
getByName(name) {
return this.dao.get(
`SELECT * FROM commands WHERE name = ?`,
[name]
);
}
getAll() {
return this.dao.all(`SELECT * FROM commands`);
}
}
module.exports = CommandRepository;