From 8e57c6a19c1b75f4d963a5e5d5880655fe09a53a Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Fri, 13 Dec 2024 14:39:34 +0100 Subject: [PATCH] Support SQLite unflagged without useless warnings Signed-off-by: Matteo Collina --- index.js | 11 ++--------- lib/cache/sqlite-cache-store.js | 6 +++++- 2 files changed, 7 insertions(+), 10 deletions(-) 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(`