Registry / database / drizzle-uncache

drizzle-uncache

JSON →
library1.0.0jsnpmunverified

A cache adapter for Drizzle ORM that uses unstorage as the backend, allowing you to plug in any unstorage driver (Redis, LRU, filesystem, Cloudflare KV, Upstash, etc.). Version 1.0.0 requires drizzle-orm >=0.45.1 and unstorage >=1.17.3. It implements Drizzle's custom cache interface and provides storage-agnostic caching with per-query TTL overrides, global caching, and debug logging. Unlike driver-specific cache solutions, this package is lightweight and unopinionated about the driver. Known not to support SQLite-based drivers (better-sqlite3, bun-sqlite, etc.) with drizzle-orm 0.45.

npm install drizzle-uncache
INSTALL
IMPORT
SIG · DRIZZLE-UNCACHE
D
drizzle-uncache
databasejavascriptv1.0.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.

unstorageCache
✓ import { unstorageCache } from 'drizzle-uncache'
✗ const { unstorageCache } = require('drizzle-uncache')
ESM-only; CommonJS require() will not work because the package is ESM. Named export, not default.
drizzle-uncache
✓ import 'drizzle-uncache'
Side-effect import is possible but not recommended; use named imports.
unstorage
✓ import { createStorage } from 'unstorage'
✗ import unstorage from 'unstorage'
unstorage exports named exports; default import is undefined.

Initializes an unstorage Redis-backed cache, connects to PostgreSQL via Drizzle, and runs a cached query.

import { unstorageCache } from 'drizzle-uncache'; import { createStorage } from 'unstorage'; import redisDriver from 'unstorage/drivers/redis'; import { drizzle } from 'drizzle-orm/node-postgres'; import { Client } from 'pg'; const storage = createStorage({ driver: redisDriver({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' }) }); const cache = unstorageCache({ storage, config: { ex: 60 } }); const client = new Client({ connectionString: process.env.DATABASE_URL ?? 'postgres://localhost/mydb' }); await client.connect(); const db = drizzle(client, { cache }); const result = await db.select().from(users).$withCache({ config: { ex: 120 } });
Debug
Known issues
breakingUnsupported SQLite-based drivers with drizzle-orm v0.45
fix
Use a different driver (Redis, LRU, fs-lite, etc.) or upgrade to a future version that may support SQLite drivers.
affects: >=1.0.0
gotcha`config` TTL fields (`ex`/`px`/`exat`/`pxat`) are converted to an absolute `expiresAt` timestamp stored with the cache entry. Some drivers ignore TTL options, but drizzle-uncache enforces expiry by checking this timestamp.
fix
Always set at least one TTL field if you want entries to expire. Use `keepTtl: true` to preserve the existing entry's TTL.
affects: >=1.0.0
gotchaThe `base` option defaults to `'drizzle:cache'`. All cache keys are prefixed with this string. If you change it after populating the cache, old entries will be ignored.
fix
Choose a consistent `base` value and do not change it after the cache is populated, or implement a migration strategy.
affects: >=1.0.0
gotchaThe `global` option caches all queries by default. If you enable it, every query will be cached unless you explicitly opt out with `.$noCache()`. This might lead to stale data if not configured carefully.
fix
Use `global: true` only after verifying that your application tolerates cached results. Use per-query `.withCache()` for selective caching.
affects: >=1.0.0
gotchaDebug logging (`debug: true`) outputs HIT/MISS and PUT/INVALIDATE messages via `console.log`. This can flood the console in production.
fix
Only enable debug in development. Remove or set `debug: false` in production.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_PACKAGE_PATH_NOT_EXPORTED: Package subpath './drivers/redis' is not defined by "exports" in .../unstorage/package.json
Importing from `unstorage/drivers/redis` without the driver package installed or using an incompatible unstorage version.
fix
Ensure `unstorage` is installed and the specific driver package (e.g., `@unstorage/driver-redis`) is installed if required. For Redis, install `ioredis` and use the correct driver path.
Cannot find module 'drizzle-uncache' or its corresponding type declarations.
The package is not installed or TypeScript cannot resolve the types. drizzle-uncache ships its own types, but the `exports` field may not be picked up by older TypeScript versions.
fix
Install drizzle-uncache: `npm install drizzle-uncache`. Ensure TypeScript >= 4.7 and set `moduleResolution: "node16"` or `"bundler"` in tsconfig.json.
Error: The "drizzle-orm" peer dependency is not installed. You must install peer dependencies yourself.
drizzle-uncache requires drizzle-orm as a peer dependency, which is not automatically installed by npm.
fix
Run `npm install drizzle-orm@^0.45.1 unstorage@^1.17.3` along with drizzle-uncache.
Error: storeItem is not a function
Incorrect usage: `unstorageCache` expects an object with `storage` property, but the user passed an unstorage instance directly.
fix
Wrap the storage in an options object: `unstorageCache({ storage: myStorage, config: { ex: 60 } })`
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
drizzle-ormrequiredPeer dependency: provides the Drizzle ORM custom cache interface and query builder
unstoragerequiredPeer dependency: provides the storage abstraction and driver system
Agent activity
12 hits · last 30 days
node
10
Resources
drizzle-uncache — npm install drizzle-uncache · libregistry