Support bun:sqlite #491

Closed
opened 2026-03-13 07:49:48 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @vedantroy on GitHub (Dec 29, 2024).

Is this suited for github?

  • Yes, this is suited for github

Is your feature request related to a problem? Please describe.

I want to use better-auth with bun, but I can't because better-sqlite3 does not work with bun, and bun:sqlite is not compatible with better-auth.

Describe the solution you'd like

For better-auth to support bun:sqlite.

Describe alternatives you've considered

Don't use Bun. Recompile better-sqlite3 from source.

Additional context

No response

Originally created by @vedantroy on GitHub (Dec 29, 2024). ### Is this suited for github? - [X] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I want to use better-auth with bun, but I can't because `better-sqlite3` does not work with bun, and `bun:sqlite` is not compatible with better-auth. ### Describe the solution you'd like For better-auth to support `bun:sqlite`. ### Describe alternatives you've considered Don't use Bun. Recompile `better-sqlite3` from source. ### Additional context _No response_
Author
Owner

@PerchunPak commented on GitHub (Feb 12, 2025):

You can use bun:sqlite like this

import type { DB } from "./db-types.d.ts";
import { BunWorkerDialect } from "kysely-bun-worker";
import { Kysely } from "kysely";

export const dialect = new BunWorkerDialect({
  url: process.env.DATABASE_URL,
});

export const auth = betterAuth({
  database: dialect,
});
@PerchunPak commented on GitHub (Feb 12, 2025): You can use `bun:sqlite` like this ```ts import type { DB } from "./db-types.d.ts"; import { BunWorkerDialect } from "kysely-bun-worker"; import { Kysely } from "kysely"; export const dialect = new BunWorkerDialect({ url: process.env.DATABASE_URL, }); export const auth = betterAuth({ database: dialect, }); ```
Author
Owner

@Xu-pixel commented on GitHub (Mar 29, 2025):

A better solution for compatiblizing with bun build.

import { BunSqliteDialect } from "kysely-bun-worker/normal";
const dialect = new BunSqliteDialect({
  url: "./db/sqlite.db",
});

export const auth = betterAuth({
  database: dialect,
})

migrate and generate

{
    "migrate": "bun x @better-auth/cli migrate --config lib/fake-auth.ts",
    "generate": "bun x @better-auth/cli generate --config lib/fake-auth.ts"
}

lib/fake-auth.ts

import Database from "better-sqlite3";
import { betterAuth } from "better-auth";

export const auth = betterAuth({
  database: new Database("./db/sqlite.db"),
});

@Xu-pixel commented on GitHub (Mar 29, 2025): A better solution for compatiblizing with bun build. ```ts import { BunSqliteDialect } from "kysely-bun-worker/normal"; const dialect = new BunSqliteDialect({ url: "./db/sqlite.db", }); export const auth = betterAuth({ database: dialect, }) ``` migrate and generate ```json { "migrate": "bun x @better-auth/cli migrate --config lib/fake-auth.ts", "generate": "bun x @better-auth/cli generate --config lib/fake-auth.ts" } ``` lib/fake-auth.ts ```ts import Database from "better-sqlite3"; import { betterAuth } from "better-auth"; export const auth = betterAuth({ database: new Database("./db/sqlite.db"), }); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#491