Skip to content

feat(drivers): add Bun-native Redis, SQLite, and Postgres adapters#120

Open
unisol1020 wants to merge 2 commits into
Julien-R44:mainfrom
unisol1020:main
Open

feat(drivers): add Bun-native Redis, SQLite, and Postgres adapters#120
unisol1020 wants to merge 2 commits into
Julien-R44:mainfrom
unisol1020:main

Conversation

@unisol1020
Copy link
Copy Markdown

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_redisbunRedisDriver, 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_sqlitebunSqliteDriver, 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_postgresbunPostgresDriver, 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).

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-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 20, 2026

🦋 Changeset detected

Latest 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant