Registry / database / cachified-adapter-sqlite

cachified-adapter-sqlite

JSON →
library1.1.0jsnpmunverified

SQLite adapter for @epic-web/cachified, version 1.1.0, allowing use of SQLite as a cache backend for the caching library. Supports multiple SQLite libraries: better-sqlite3, sqlite, sqlite3, bun:sqlite, and node:sqlite. It provides separate subpath exports for each SQLite driver, ensuring type-safety with TypeScript. The adapter simplifies integration by handling table creation and cache operations. Key differentiator: compatibility with a wide range of SQLite drivers, while the base @epic-web/cachified only provides in-memory and Redis adapters out of the box. Regular updates follow the host library's release cadence.

npm install cachified-adapter-sqlite
INSTALL
IMPORT
SIG · CACHIFIED-ADAPTER-
C
cachified-adapter-sqlite
databasejavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

betterSqlite3CacheAdapter
import { betterSqlite3CacheAdapter } from 'cachified-adapter-sqlite/better-sqlite3'
import { betterSqlite3CacheAdapter } from 'cachified-adapter-sqlite'
Subpath import required; default export only for common entry point. Use specific subpath depending on SQLite driver.
sqlite3CacheAdapter
import { sqlite3CacheAdapter } from 'cachified-adapter-sqlite/sqlite3'
const { sqlite3CacheAdapter } = require('cachified-adapter-sqlite')
ESM-only package. CommonJS require will not work; use dynamic import if needed.
createNodeSqliteCacheTable
import { createNodeSqliteCacheTable } from 'cachified-adapter-sqlite/node-sqlite'
import { createNodeSqliteCacheTable } from 'cachified-adapter-sqlite'
Table creation function is exported only from the driver-specific subpath, not from the main entry.

Creates an in-memory SQLite cache using better-sqlite3 and retrieves a cached value with cachified.

import { cachified } from '@epic-web/cachified'; import { betterSqlite3CacheAdapter, createBetterSqlite3CacheTable } from 'cachified-adapter-sqlite/better-sqlite3'; import Database from 'better-sqlite3'; const db = new Database(':memory:'); const tableName = 'cache'; createBetterSqlite3CacheTable(db, tableName); const cache = betterSqlite3CacheAdapter({ database: db, tableName }); async function main() { const result = await cachified({ key: 'example', cache, getFreshValue: () => Promise.resolve('fresh value'), ttl: 60_000, }); console.log(result); } main();
Debug
Known issues
breakingESM-only package: CommonJS require() will not work and throws a runtime error
fix
Use import syntax or dynamic import. For Node.js, set type: "module" in package.json or use .mjs extension.
affects: >=1.0.0
gotchaMissing @epic-web/cachified peer dependency will cause runtime errors when using cache adapters
fix
Install the peer dependency: npm install @epic-web/cachified@^5.2.0
affects: >=1.0.0
gotchaTable must be created before initializing the cache adapter; adapter will fail if table does not exist
fix
Call create*CacheTable function (e.g., createBetterSqlite3CacheTable(database, tableName)) before creating the cache adapter.
affects: >=1.0.0
deprecatedAdapting older SQLite drivers without TypeScript support may cause type errors; the package assumes typed drivers
fix
Use the recommended driver versions (better-sqlite3 >=11.7.0, sqlite >=5.1.1, sqlite3 >=5.1.7).
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'cachified-adapter-sqlite/better-sqlite3'
Subpath import not supported by older Node.js versions or missing package.json exports field resolution.
fix
Ensure Node.js version >=14.13 (or use --experimental-exports flag). Update to latest Node LTS.
Error: SQLITE_ERROR: no such table: cache
Table not created before initializing cache adapter.
fix
Call createBetterSqlite3CacheTable(database, 'cache') or equivalent before creating the adapter.
TypeError: (intermediate value).get is not a function
Missing database instance or wrong type passed to adapter. The adapter expects a specific driver instance.
fix
Pass the correct database object from the corresponding SQLite library (e.g., new Database(...) from better-sqlite3).
ERR_PACKAGE_PATH_NOT_EXPORTED: Package subpath './xxx' is not defined by "exports"
Using an invalid subpath (e.g., 'cachified-adapter-sqlite/bun-sqlite' instead of 'cachified-adapter-sqlite/bun').
fix
Use correct subpath: /better-sqlite3, /sqlite, /sqlite3, /bun, or /node-sqlite.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
@epic-web/cachifiedrequiredPeer dependency required for cache operations, defines the caching interface. At version ^5.2.0.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
cachified-adapter-sqlite — npm install cachified-adapter-sqlite · libregistry