UNPKG

724 BJavaScriptView Raw
1'use strict';
2
3const KeyvSql = require('@keyv/sql');
4const sqlite3 = require('sqlite3');
5const pify = require('pify');
6
7class 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
34module.exports = KeyvSqlite;