Skip to content

Commit ff18d8c

Browse files
authored
Support SQLite unflagged without useless warnings (#3947)
Signed-off-by: Matteo Collina <[email protected]>
1 parent 02e73f8 commit ff18d8c

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

index.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,8 @@ module.exports.cacheStores = {
4949
MemoryCacheStore: require('./lib/cache/memory-cache-store')
5050
}
5151

52-
try {
53-
const SqliteCacheStore = require('./lib/cache/sqlite-cache-store')
54-
module.exports.cacheStores.SqliteCacheStore = SqliteCacheStore
55-
} catch (err) {
56-
// Most likely node:sqlite was not present, since SqliteCacheStore is
57-
// optional, don't throw. Don't check specific error codes here because while
58-
// ERR_UNKNOWN_BUILTIN_MODULE is expected, users have seen other codes like
59-
// MODULE_NOT_FOUND
60-
}
52+
const SqliteCacheStore = require('./lib/cache/sqlite-cache-store')
53+
module.exports.cacheStores.SqliteCacheStore = SqliteCacheStore
6154

6255
module.exports.buildConnector = buildConnector
6356
module.exports.errors = errors

lib/cache/sqlite-cache-store.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict'
22

3-
const { DatabaseSync } = require('node:sqlite')
43
const { Writable } = require('stream')
54
const { assertCacheKey, assertCacheValue } = require('../util/cache.js')
65

6+
let DatabaseSync
7+
78
const VERSION = 3
89

910
// 2gb
@@ -101,6 +102,9 @@ module.exports = class SqliteCacheStore {
101102
}
102103
}
103104

105+
if (!DatabaseSync) {
106+
DatabaseSync = require('node:sqlite').DatabaseSync
107+
}
104108
this.#db = new DatabaseSync(opts?.location ?? ':memory:')
105109

106110
this.#db.exec(`

0 commit comments

Comments
 (0)