Skip to content

Commit

Permalink
Support SQLite unflagged without useless warnings (#3947)
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina authored Dec 13, 2024
1 parent 02e73f8 commit ff18d8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 2 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/cache/sqlite-cache-store.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(`
Expand Down

0 comments on commit ff18d8c

Please sign in to comment.