diff --git a/index.js b/index.js index 4c44c678df7..f31e10e9114 100644 --- a/index.js +++ b/index.js @@ -49,15 +49,8 @@ module.exports.cacheStores = { MemoryCacheStore: require('./lib/cache/memory-cache-store') } -try { - const SqliteCacheStore = require('./lib/cache/sqlite-cache-store') - module.exports.cacheStores.SqliteCacheStore = SqliteCacheStore -} catch (err) { - // Most likely node:sqlite was not present, since SqliteCacheStore is - // optional, don't throw. Don't check specific error codes here because while - // ERR_UNKNOWN_BUILTIN_MODULE is expected, users have seen other codes like - // MODULE_NOT_FOUND -} +const SqliteCacheStore = require('./lib/cache/sqlite-cache-store') +module.exports.cacheStores.SqliteCacheStore = SqliteCacheStore module.exports.buildConnector = buildConnector module.exports.errors = errors diff --git a/lib/cache/sqlite-cache-store.js b/lib/cache/sqlite-cache-store.js index 3a4d1d4dac2..a5afc829413 100644 --- a/lib/cache/sqlite-cache-store.js +++ b/lib/cache/sqlite-cache-store.js @@ -1,9 +1,10 @@ 'use strict' -const { DatabaseSync } = require('node:sqlite') const { Writable } = require('stream') const { assertCacheKey, assertCacheValue } = require('../util/cache.js') +let DatabaseSync + const VERSION = 3 // 2gb @@ -101,6 +102,9 @@ module.exports = class SqliteCacheStore { } } + if (!DatabaseSync) { + DatabaseSync = require('node:sqlite').DatabaseSync + } this.#db = new DatabaseSync(opts?.location ?? ':memory:') this.#db.exec(`