Prisma
Prisma 7 generates a TypeScript client from schema.prisma and talks to the database through a driver adapter, so the same libSQL, Postgres or MySQL drivers serve it.
Prisma 7 generates a TypeScript client from schema.prisma and talks to the database through a driver adapter, so the same
libSQL, Postgres or MySQL drivers serve it. There is no query-engine binary to bundle, which makes it work on the same runtimes as
the clients above.
The schema names the generator's output folder; the generated client is a source folder you import from, not a package:
generator client {
provider = "prisma-client"
output = "../src/server/generated"
}
datasource db {
provider = "sqlite"
}
model Note {
id Int @id @default(autoincrement())
title String @unique
owner String
}
Run npx prisma generate before dusk dev and dusk build (add it to the predev and prebuild scripts, or to postinstall), and
npx prisma migrate deploy when you deploy. The connection module has the shape of the Drizzle one, with the adapter in place of
the driver:
import { PrismaLibSql } from "@prisma/adapter-libsql";
import { PrismaClient } from "./generated/client";
function open(): PrismaClient {
const authToken = process.env["DATABASE_AUTH_TOKEN"];
return new PrismaClient({
adapter: new PrismaLibSql({
url: process.env["DATABASE_URL"] ?? "file:./dev.db",
...(authToken === undefined ? {} : { authToken }),
}),
});
}
const shared = globalThis as typeof globalThis & { __prisma?: PrismaClient };
export const prisma = (shared.__prisma ??= open());
import { HttpError, serverFn } from "@shadow-js/dusk/server";
import { Prisma } from "./generated/client";
import { newNote } from "../schema";
import { prisma } from "./prisma.server";
export const addNote = serverFn({ input: newNote }, async ({ title }) => {
try {
return await prisma.note.create({ data: { title, owner: "anonymous" } });
} catch (error) {
// P2002 is Prisma's unique-constraint error.
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") {
throw new HttpError(409, "That title exists");
}
throw error;
}
});