Reuse an existing Drizzle connection
A Better Auth application already uses Drizzle ORM for persistence.
Better Auth · Const
drizzleAdapter connects Better Auth to a configured Drizzle ORM database. Pass the database instance and its provider, such as sqlite, pg, or mysql.
drizzleAdapter wraps an existing Drizzle database connection so Better Auth can use it as its database adapter. Supply the database instance and identify the SQL provider; the adapter package also supports a separate Relations v2 entry point.
drizzleAdapter(db, { provider: "sqlite" | "pg" | "mysql" })| Name | Type | Description |
|---|---|---|
db | Drizzle database instance | A configured Drizzle ORM database instance. |
options.provider | "sqlite" | "pg" | "mysql" | The SQL dialect used by the database connection: sqlite, pg, or mysql. |
A Better Auth database adapter configured to use the supplied Drizzle connection.
drizzleAdapter.import { betterAuth } from "better-auth";
import { drizzleAdapter } from "@better-auth/drizzle-adapter";
import { db } from "./database";
export const auth = betterAuth({
database: drizzleAdapter(db, { provider: "sqlite" })
});Pass the configured Drizzle database and its dialect to Better Auth's database option.
A Better Auth application already uses Drizzle ORM for persistence.
An application targets SQLite, PostgreSQL, or MySQL.
A project needs Better Auth's generated tables in a Drizzle schema.
drizzleAdapter configure?It is the Better Auth database adapter for a Drizzle ORM connection. Configure it by passing the Drizzle database instance and a provider such as sqlite, pg, or mysql.
Follow-up: How would you support Drizzle Relations v2? Import drizzleAdapter from @better-auth/drizzle-adapter/relations-v2 and configure it with the auth schema as documented.
The provider identifies the database dialect used by the Drizzle connection. The documented values are SQLite, PostgreSQL, and MySQL, represented as sqlite, pg, and mysql.
Follow-up: What should be checked if generated relations or joins fail? Verify that the Drizzle schema contains the necessary relations and that the relevant Better Auth joins setting is enabled.
Install @better-auth/drizzle-adapter, create or obtain the Drizzle database instance, and pass it to drizzleAdapter inside Better Auth's database configuration. Generate the Better Auth schema with the CLI before applying ORM migrations.
Follow-up: Where does generated Drizzle schema output go? The CLI documentation says it is written to schema.ts in the project root by default.
betterAuth@better-auth/drizzle-adapter/relations-v2advanced.database.joinsgenerate