[PR #7020] feat(adapters): add Bun SQL adapter for PostgreSQL #7028

Open
opened 2026-03-13 13:21:45 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7020
Author: @kimchi-developer
Created: 12/27/2025
Status: 🔄 Open

Base: canaryHead: feat/bun-sql-adapter


📝 Commits (1)

  • 115386d feat(adapters): add Bun SQL adapter for PostgreSQL

📊 Changes

7 files changed (+468 additions, -2 deletions)

View changed files

📝 docker-compose.yml (+13 -1)
📝 packages/better-auth/package.json (+14 -0)
packages/better-auth/src/adapters/bun-sql-adapter/bun-sql-adapter.ts (+319 -0)
packages/better-auth/src/adapters/bun-sql-adapter/index.ts (+1 -0)
packages/better-auth/src/adapters/bun-sql-adapter/test/adapter.bun-sql.pg.number-id.test.ts (+52 -0)
packages/better-auth/src/adapters/bun-sql-adapter/test/adapter.bun-sql.pg.test.ts (+66 -0)
📝 packages/better-auth/src/adapters/create-test-suite.ts (+3 -1)

📄 Description

Summary

Add a native Bun SQL adapter using Bun's built-in PostgreSQL driver (bun:sql).

Features

  • Full CRUD operations (create, findOne, findMany, update, updateMany, delete, deleteMany, count)
  • Transaction support with automatic rollback on error
  • Support for all WHERE operators (eq, ne, gt, gte, lt, lte, in, not_in, contains, starts_with, ends_with)
  • Support for numeric IDs (useNumberId option)
  • Support for JSON, dates, and booleans

Usage

import { betterAuth } from "better-auth";
import { bunSqlAdapter } from "better-auth/adapters/bun-sql";
import { SQL } from "bun";

const sql = new SQL({
  hostname: "localhost",
  port: 5432,
  database: "my_database",
  username: "user",
  password: "password",
});

export const auth = betterAuth({
  database: bunSqlAdapter({
    sql,
    transaction: true, // Enable transaction support
  }),
  // ... other options
});

Test Results

  • 70/70 main tests passed
  • 60/60 number-id tests passed

Bug Fix

Also fixes a bug in create-test-suite.ts where the transaction function was incorrectly referenced (adapter.transaction instead of adapter.options?.adapterConfig.transaction), causing transaction tests to fail on subsequent calls for adapters that support transactions.

Test Plan

  • All 130 adapter tests pass
  • Transaction rollback works correctly
  • Number ID support works correctly
  • All WHERE operators work correctly

Summary by cubic

Adds a native Bun SQL adapter for PostgreSQL using bun:sql. This lets Better Auth run on Bun without an ORM, with full CRUD and transaction support.

  • New Features

    • Bun SQL adapter for PostgreSQL (bun:sql) with create/find/update/delete and count.
    • Transactions with automatic rollback.
    • Supports JSON, dates, booleans, numeric IDs, and all WHERE operators.
    • Added package export and docker-compose service; new tests for the adapter with all 130 adapter tests passing.
  • Bug Fixes

    • Corrected transaction function reference in create-test-suite to use adapter.options?.adapterConfig.transaction, fixing failures on subsequent transaction tests.

Written for commit 115386dc5a. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7020 **Author:** [@kimchi-developer](https://github.com/kimchi-developer) **Created:** 12/27/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/bun-sql-adapter` --- ### 📝 Commits (1) - [`115386d`](https://github.com/better-auth/better-auth/commit/115386dc5aa6d60447fec2b801bf76035126ddee) feat(adapters): add Bun SQL adapter for PostgreSQL ### 📊 Changes **7 files changed** (+468 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docker-compose.yml` (+13 -1) 📝 `packages/better-auth/package.json` (+14 -0) ➕ `packages/better-auth/src/adapters/bun-sql-adapter/bun-sql-adapter.ts` (+319 -0) ➕ `packages/better-auth/src/adapters/bun-sql-adapter/index.ts` (+1 -0) ➕ `packages/better-auth/src/adapters/bun-sql-adapter/test/adapter.bun-sql.pg.number-id.test.ts` (+52 -0) ➕ `packages/better-auth/src/adapters/bun-sql-adapter/test/adapter.bun-sql.pg.test.ts` (+66 -0) 📝 `packages/better-auth/src/adapters/create-test-suite.ts` (+3 -1) </details> ### 📄 Description ## Summary Add a native Bun SQL adapter using Bun's built-in PostgreSQL driver (`bun:sql`). ### Features - Full CRUD operations (create, findOne, findMany, update, updateMany, delete, deleteMany, count) - Transaction support with automatic rollback on error - Support for all WHERE operators (eq, ne, gt, gte, lt, lte, in, not_in, contains, starts_with, ends_with) - Support for numeric IDs (`useNumberId` option) - Support for JSON, dates, and booleans ### Usage ```typescript import { betterAuth } from "better-auth"; import { bunSqlAdapter } from "better-auth/adapters/bun-sql"; import { SQL } from "bun"; const sql = new SQL({ hostname: "localhost", port: 5432, database: "my_database", username: "user", password: "password", }); export const auth = betterAuth({ database: bunSqlAdapter({ sql, transaction: true, // Enable transaction support }), // ... other options }); ``` ### Test Results - **70/70** main tests passed - **60/60** number-id tests passed ### Bug Fix Also fixes a bug in `create-test-suite.ts` where the transaction function was incorrectly referenced (`adapter.transaction` instead of `adapter.options?.adapterConfig.transaction`), causing transaction tests to fail on subsequent calls for adapters that support transactions. ## Test Plan - [x] All 130 adapter tests pass - [x] Transaction rollback works correctly - [x] Number ID support works correctly - [x] All WHERE operators work correctly <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds a native Bun SQL adapter for PostgreSQL using bun:sql. This lets Better Auth run on Bun without an ORM, with full CRUD and transaction support. - **New Features** - Bun SQL adapter for PostgreSQL (bun:sql) with create/find/update/delete and count. - Transactions with automatic rollback. - Supports JSON, dates, booleans, numeric IDs, and all WHERE operators. - Added package export and docker-compose service; new tests for the adapter with all 130 adapter tests passing. - **Bug Fixes** - Corrected transaction function reference in create-test-suite to use adapter.options?.adapterConfig.transaction, fixing failures on subsequent transaction tests. <sup>Written for commit 115386dc5aa6d60447fec2b801bf76035126ddee. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:21:45 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#7028