-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathnode-sqlite.js
More file actions
36 lines (34 loc) · 960 Bytes
/
node-sqlite.js
File metadata and controls
36 lines (34 loc) · 960 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
const { DatabaseSync } = require('node:sqlite');
class NodeSqlite extends DatabaseSync {
prepare(sql) {
const stmt = super.prepare(sql)
const ret = {
run(params) {
try {
params = Array.isArray(params) ? params : [params]
return stmt.run(...params)
} catch (err) {
if (err.message.indexOf('NOT NULL constraint failed:') === 0) {
err.code = 'SQLITE_CONSTRAINT_NOTNULL'
}
throw err
}
},
get(params) {
params = Array.isArray(params) ? params : [params]
return stmt.get(...params)
},
all(params) {
params = Array.isArray(params) ? params : [params]
return stmt.all(...params)
},
iterate(params) {
stmt.setReturnArrays(true)
params = Array.isArray(params) ? params : [params]
return stmt.iterate(...params)
}
}
return ret
}
}
module.exports = NodeSqlite