Prisma banner

Prerequisites

Before you start, make sure you:

1

Install the libSQL SDK and its Prisma driver

npm install @libsql/client @prisma/adapter-libsql
2

Configure database credentials

Get the database URL:

turso db show --url <database-name>

Get the database authentication token:

turso db tokens create <database-name>

Assign credentials to the environment variables inside .env.local:

TURSO_DATABASE_URL="..."
TURSO_AUTH_TOKEN="..."
3

Enable the `driverAdapters` Preview feature flag:

prisma/schema.prisma 3
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["driverAdapters"]
}
4

Generate Prisma client

npx prisma generate
5

Update your Prisma Client Instance

import { PrismaClient } from "@prisma/client";
import { PrismaLibSQL } from "@prisma/adapter-libsql";
import { createClient } from "@libsql/client";

const libsql = createClient({
  url: process.env.TURSO_DATABASE_URL,
  authToken: process.env.TURSO_AUTH_TOKEN,
});

const adapter = new PrismaLibSQL(libsql);
const prisma = new PrismaClient({ adapter });
6

Query your database

const response = await prisma.table_name.findMany();