Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Better Auth · Const

drizzleAdapter

drizzleAdapter connects Better Auth to a configured Drizzle ORM database. Pass the database instance and its provider, such as sqlite, pg, or mysql.

How it works

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.

Syntax

drizzleAdapter(db, { provider: "sqlite" | "pg" | "mysql" })

Parameters

NameTypeDescription
dbDrizzle database instanceA configured Drizzle ORM database instance.
options.provider"sqlite" | "pg" | "mysql"The SQL dialect used by the database connection: sqlite, pg, or mysql.

Returns

A Better Auth database adapter configured to use the supplied Drizzle connection.

Key points

  • Install the dedicated adapter package before importing drizzleAdapter.
  • Provide the Drizzle database instance as the first argument.
  • Set the provider to the dialect used by the connection: SQLite, PostgreSQL, or MySQL.
  • Use Better Auth's schema generator to create the ORM schema it requires.
  • Enable advanced database joins explicitly when using that feature.
  • Select the Relations v2 adapter entry point when the project uses Drizzle Relations v2.

Common mistakes

  • Install and configure Drizzle before initializing the adapter.
  • The default entry point is for Drizzle Relations v1; use the Relations v2 entry point when needed.
  • Schemas using joins must define the required Drizzle relations.

Example: Configure the Drizzle adapter

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.

When to use it

Reuse an existing Drizzle connection

A Better Auth application already uses Drizzle ORM for persistence.

Select the database dialect

An application targets SQLite, PostgreSQL, or MySQL.

Generate ORM schema

A project needs Better Auth's generated tables in a Drizzle schema.

Interview questions

QWhat does 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.

QWhy is the provider option required?

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.

QWhat is the recommended setup sequence?

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-v2
  • advanced.database.joins
  • generate

Source: Drizzle ORM Adapter. Checked 2026-10-15.