1 | 'use strict';
|
2 |
|
3 | const KeyvSql = require('@keyv/sql');
|
4 | const sqlite3 = require('sqlite3');
|
5 | const pify = require('pify');
|
6 |
|
7 | class KeyvSqlite extends KeyvSql {
|
8 | constructor(options) {
|
9 | options = Object.assign({
|
10 | dialect: 'sqlite',
|
11 | uri: 'sqlite://:memory:',
|
12 | }, options);
|
13 | options.db = options.uri.replace(/^sqlite:\/\//, '');
|
14 |
|
15 | options.connect = () => new Promise((resolve, reject) => {
|
16 | const db = new sqlite3.Database(options.db, error => {
|
17 | if (error) {
|
18 | reject(error);
|
19 | } else {
|
20 | if (options.busyTimeout) {
|
21 | db.configure('busyTimeout', options.busyTimeout);
|
22 | }
|
23 |
|
24 | resolve(db);
|
25 | }
|
26 | });
|
27 | })
|
28 | .then(db => pify(db.all).bind(db));
|
29 |
|
30 | super(options);
|
31 | }
|
32 | }
|
33 |
|
34 | module.exports = KeyvSqlite;
|