Prerequisites

Before you start, make sure you:

1

Install the libSQL SDK and its Prisma driver

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

Retrieve 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.

TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=
3

Enable the `driverAdapters` preview feature flag:

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

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}
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

Database Migrations

Prisma Migrate and Introspection workflows are currently not supported when working with Turso — learn more.

First, generate a migration file using prisma migrate dev against a local SQLite database

npx prisma migrate dev --name init

Then, apply the migration to your Turso database using the Turso’s CLI

turso db shell turso-prisma-db < ./prisma/migrations/20230922132717_init/migration.sql

Replace 20230922132717_init with the name of your migration created from the npx prisma migrate dev command.

7

Query

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