https://github.com/ilbertt/better-auth-bun-sql
A better-auth database adapter for Bun's built-in SQL module
https://github.com/ilbertt/better-auth-bun-sql
better-auth bun sql typescript
Last synced: about 5 hours ago
JSON representation
A better-auth database adapter for Bun's built-in SQL module
- Host: GitHub
- URL: https://github.com/ilbertt/better-auth-bun-sql
- Owner: ilbertt
- License: unlicense
- Created: 2026-06-15T14:19:51.000Z (6 days ago)
- Default Branch: main
- Last Pushed: 2026-06-15T16:06:46.000Z (6 days ago)
- Last Synced: 2026-06-15T16:26:12.335Z (6 days ago)
- Topics: better-auth, bun, sql, typescript
- Language: TypeScript
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# @ilbertt/better-auth-bun-sql
A [better-auth](https://better-auth.com) database adapter for Bun's built-in SQL module ([`bun:sql`](https://bun.com/docs/runtime/sql)).
## Installation
```sh
bun add @ilbertt/better-auth-bun-sql
```
> Requires [Bun](https://bun.com) — this adapter relies on the `bun:sql` runtime module and does not work on Node.js.
## Usage
Pass a `bun:sql` instance — connected to Postgres or SQLite — to `bunSqlAdapter`:
```ts
import { betterAuth } from 'better-auth';
import { SQL } from 'bun';
import { bunSqlAdapter } from '@ilbertt/better-auth-bun-sql';
const sql = new SQL(process.env.DATABASE_URL); // e.g. postgres://… or sqlite://…
export const auth = betterAuth({
database: bunSqlAdapter({ sql }),
});
```
### Options
| Option | Type | Default | Description |
| ----------- | ------------------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `sql` | `SQL` | - | **Required.** A `bun:sql` instance connected to a Postgres or SQLite database. |
| `schema` | `string` | - | Database schema (namespace) the tables live in. When omitted, table names are unqualified and resolved against the connection's `search_path`. |
| `usePlural` | `boolean` | `false` | Pluralize table names (`user` → `users`). |
| `debugLogs` | `DBAdapterDebugLogOption` | `false` | better-auth adapter debug logging. |
## Supported databases
`bun:sql` speaks Postgres, SQLite, and MySQL/MariaDB, but this adapter supports **Postgres and SQLite only**. MySQL/MariaDB lack the `RETURNING` clause the adapter relies on for `create`/`update`, so they are intentionally unsupported (the adapter throws on a MySQL/MariaDB connection). The dialect is detected automatically from the `bun:sql` instance.
## Contributing
See [CONTRIBUTING.md](./.github/CONTRIBUTING.md).