feat(drivers): add Bun-native Redis, SQLite, and Postgres adapters#120
Open
unisol1020 wants to merge 2 commits into
Open
feat(drivers): add Bun-native Redis, SQLite, and Postgres adapters#120unisol1020 wants to merge 2 commits into
unisol1020 wants to merge 2 commits into
Conversation
Adds first-class support for Bun runtime users by introducing three new
driver entry points that talk to Bun's built-in clients directly,
bypassing the Node-targeted bindings used by the existing drivers.
Existing drivers stay untouched — Bun is an opt-in alternative, not a
replacement.
New drivers (all L2, Bun runtime only):
- `bentocache/drivers/bun_redis` → `bunRedisDriver`, uses
`import { RedisClient } from 'bun'`. No ioredis dependency.
Implements get/set (PX TTL)/pull (GETDEL)/delete/deleteMany (UNLINK)/
clear (SCAN + UNLINK loop)/namespace/disconnect.
- `bentocache/drivers/bun_sqlite` → `bunSqliteDriver`, plugs a new
`BunSqliteAdapter` into the existing `DatabaseDriver`. Uses
`bun:sqlite` Database + prepared statements (lazily built so they
reference the table only after `setTableName`). `deleteMany` runs
inside a single transaction.
- `bentocache/drivers/bun_postgres` → `bunPostgresDriver`, plugs
`BunPostgresAdapter` into `DatabaseDriver`. Built on
`import { SQL } from 'bun'` tagged-template queries with identifier
interpolation via `sql(tableName)`. Same column shape as the existing
Kysely PG path (key PK, value TEXT, expires_at BIGINT). Postgres has
no native TTL so users should set `pruneInterval` — same caveat as the
existing pg adapters.
Runtime compatibility:
- No `engines` restriction; Node users see no behaviour change.
- All Bun imports in the type layer use `import type` only, so
`drivers_options.ts` still loads cleanly under Node.
- `require('bun')` / `require('bun:sqlite')` live only inside the new
driver files. A Node user accidentally importing them gets a clear
ERR_MODULE_NOT_FOUND.
Tests:
- Three new spec files under `tests/drivers/bun_*.spec.ts` that gate
registration on `typeof Bun !== 'undefined'` and dynamically import
the driver inside the guard, so Japa loads them on Node without
resolving Bun-only modules. Reuse `registerCacheDriverTestSuite` for
the standard get/set/pull/delete/deleteMany/clear/namespace/TTL
coverage.
- New `quick:test:bun` script (`bun bin/test.ts`) for running the Bun
specs locally.
- Verified end-to-end: Node typecheck/lint/build clean; Node tests run
unchanged (existing memory/redis suites pass, Bun specs report
NO TESTS EXECUTED); under Bun, all three specs pass (22 + 21 + 21).
Docs:
- `quick_setup.md` and `telemetry.md` codegroups gain a `bun` tab next
to npm/pnpm/yarn.
- `packages/otel/README.md` install block now lists all four package
managers.
- `cache_drivers.md` gets three new sections (Bun Redis, Bun SQLite,
Bun Postgres). Each is explicitly tagged "L2 driver, Bun runtime
only" so the topology constraint is discoverable in-page.
Package wiring:
- Three new `./drivers/bun_*` entries in `package.json` exports map.
- `@types/bun` added to devDependencies (no peerDep — Bun is a runtime,
not an npm package consumers install).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: bb8060a The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Add Bun-native Redis, SQLite, and Postgres adapters to drivers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds first-class support for Bun runtime users by introducing three new driver entry points that talk to Bun's built-in clients directly, bypassing the Node-targeted bindings used by the existing drivers. Existing drivers stay untouched — Bun is an opt-in alternative, not a replacement.
New drivers (all L2, Bun runtime only):
bentocache/drivers/bun_redis→bunRedisDriver, usesimport { RedisClient } from 'bun'. No ioredis dependency. Implements get/set (PX TTL)/pull (GETDEL)/delete/deleteMany (UNLINK)/ clear (SCAN + UNLINK loop)/namespace/disconnect.bentocache/drivers/bun_sqlite→bunSqliteDriver, plugs a newBunSqliteAdapterinto the existingDatabaseDriver. Usesbun:sqliteDatabase + prepared statements (lazily built so they reference the table only aftersetTableName).deleteManyruns inside a single transaction.bentocache/drivers/bun_postgres→bunPostgresDriver, plugsBunPostgresAdapterintoDatabaseDriver. Built onimport { SQL } from 'bun'tagged-template queries with identifier interpolation viasql(tableName). Same column shape as the existing Kysely PG path (key PK, value TEXT, expires_at BIGINT). Postgres has no native TTL so users should setpruneInterval— same caveat as the existing pg adapters.Runtime compatibility:
enginesrestriction; Node users see no behaviour change.import typeonly, sodrivers_options.tsstill loads cleanly under Node.require('bun')/require('bun:sqlite')live only inside the new driver files. A Node user accidentally importing them gets a clear ERR_MODULE_NOT_FOUND.Tests:
tests/drivers/bun_*.spec.tsthat gate registration ontypeof Bun !== 'undefined'and dynamically import the driver inside the guard, so Japa loads them on Node without resolving Bun-only modules. ReuseregisterCacheDriverTestSuitefor the standard get/set/pull/delete/deleteMany/clear/namespace/TTL coverage.quick:test:bunscript (bun bin/test.ts) for running the Bun specs locally.Docs:
quick_setup.mdandtelemetry.mdcodegroups gain abuntab next to npm/pnpm/yarn.packages/otel/README.mdinstall block now lists all four package managers.cache_drivers.mdgets three new sections (Bun Redis, Bun SQLite, Bun Postgres). Each is explicitly tagged "L2 driver, Bun runtime only" so the topology constraint is discoverable in-page.Package wiring:
./drivers/bun_*entries inpackage.jsonexports map.@types/bunadded to devDependencies (no peerDep — Bun is a runtime, not an npm package consumers install).