/[sudobot]/trunk/src/Database.js
ViewVC logotype

Annotation of /trunk/src/Database.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 45 - (hide annotations)
Mon Jul 29 17:28:20 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 1458 byte(s)
Release version 1.8.0

* Added setTimeout() and DB combination support so that the timeouts would never get lost even if the bot stops
* Added messages scheduling, expiring and both in one support
1 rakin 5 const { Database: DB } = require('sqlite3');
2    
3     class Database {
4     constructor(dbpath) {
5     this.dbpath = dbpath;
6     this.db = new DB(dbpath, (err) => {
7     if (err) {
8     console.log(err);
9     }
10     });
11     }
12    
13     get(sql, callback1, callback2) {
14     return this.db.get(sql, callback1, callback2);
15     }
16    
17     all(sql, callback1, callback2) {
18     return this.db.all(sql, callback1, callback2);
19     }
20 rakin 45
21     runAsync(sql, paramsOrCallback = []) {
22     return new Promise((resolve, reject) => {
23     this.db.run(sql, paramsOrCallback, err => {
24     if (err) {
25     reject(err);
26     return;
27     }
28    
29     resolve();
30     });
31     });
32     }
33    
34     getAsync(sql, paramsOrCallback = []) {
35     return new Promise((resolve, reject) => {
36     this.db.get(sql, paramsOrCallback, (err, data) => {
37     if (err) {
38     reject(err);
39     return;
40     }
41    
42     resolve(data);
43     });
44     });
45     }
46    
47     allAsync(sql, paramsOrCallback = []) {
48     return new Promise((resolve, reject) => {
49     this.db.all(sql, paramsOrCallback, (err, data) => {
50     if (err) {
51     reject(err);
52     return;
53     }
54    
55     resolve(data);
56     });
57     });
58     }
59 rakin 5 }
60    
61     module.exports = Database;

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26