docs/content/docs/adapters/prisma.mdx
Prisma ORM is an open-source database toolkit that simplifies database access and management in applications by providing a type-safe query builder and an intuitive data modeling interface.
Before getting started, make sure you have Prisma installed and configured. For more information, see Prisma Documentation
To use the Prisma adapter, you need to install the @better-auth/prisma-adapter package:
@better-auth/prisma-adapter
You can use the Prisma adapter to connect to your database as follows.
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "sqlite",
}),
});
The Better Auth CLI allows you to generate or migrate your database schema based on your Better Auth configuration and plugins.
<table> <thead> <tr className="border-b"> <th> <p className="font-bold text-[16px] mb-1">Prisma Schema Generation</p> </th> <th>
<p className="font-bold text-[16px] mb-1">Prisma Schema Migration</p>
</th>
</tr>
npx auth@latest generate
Database joins is useful when Better-Auth needs to fetch related data from multiple tables in a single query.
Endpoints like /get-session, /get-full-organization and many others benefit greatly from this feature,
seeing upwards of 2x to 3x performance improvements depending on database latency.
The Prisma adapter supports joins out of the box since version 1.4.0.
To enable this feature, you need to set the experimental.joins option to true in your auth configuration.
import { betterAuth } from "better-auth";
export const auth = betterAuth({
experimental: { joins: true }
});