Skip to main content
Drizzle ORM is a type-safe SQL query builder and ORM for TypeScript. Better Auth ships a first-class Drizzle adapter that supports PostgreSQL, MySQL, and SQLite.

Installation

1

Install Drizzle ORM and the Better Auth adapter

2

Configure the adapter

Import drizzleAdapter from better-auth/adapters/drizzle and pass your Drizzle db instance:
auth.ts

Configuration options

The drizzleAdapter function accepts a Drizzle db instance and a config object:

Schema generation

The Better Auth CLI generates the required Drizzle schema based on your auth configuration and any plugins you have enabled.
After generating the schema file, apply it to your database with Drizzle Kit:

Schema examples

The tables below are what npx auth@latest generate produces for each provider.
schema.ts

Modifying table names

If your Drizzle schema uses different table export names (for example users instead of user), pass the schema object and remap the key:
auth.ts
Alternatively, configure modelName directly in the auth config:
auth.ts

Modifying field names

Better Auth maps field names using the property name you assign in your Drizzle schema. To rename a column in the database without changing the property name, update the column string argument:
You can also map field names through the auth config:
auth.ts

Using plural table names

If every table in your schema uses a plural name, pass usePlural: true instead of remapping each model:
auth.ts

Experimental joins

Enabling joins allows Better Auth to fetch related data in a single query rather than issuing multiple round-trips. Endpoints such as /get-session and /get-full-organization see 2-3x latency improvements.
auth.ts
Joins require Drizzle relations definitions in your schema. Run npx auth@latest generate with the latest CLI to produce a schema that includes them. You must also pass each relation through the adapter’s schema object.