Step 1 — the datasource

# .env — note sslmode=disable (cleartext listener)
DATABASE_URL="postgresql://[email protected]:5433/main?sslmode=disable"
// schema.prisma
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model Note {
  id   Int    @id
  body String
  ts   String
}

Breakdown: the postgresql provider speaks the wire protocol the server implements. Model fields use types the engine supports (Int, String).

Step 2 — runtime queries

import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

const recent = await prisma.note.findMany({ take: 50, orderBy: { id: "desc" } });

await prisma.note.create({ data: { id: 1, body: "hello", ts: new Date().toISOString() } });

await prisma.$transaction([
  prisma.note.update({ where: { id: 1 }, data: { body: "edited" } }),
]);

Breakdown: findMany, create, update, and $transaction compile to parameterized SQL the engine runs. As with any client, a query that exceeds the surface returns a clean ENGINE_ERR_SQL — verify advanced filters against the SQL reference.

The caveat: don't use prisma migrate (yet)

Manage schema with plain SQL, then point Prisma at it

Prisma's migration engine emits advanced DDL and probes catalog features beyond the current surface, so prisma migrate and db push are the rough edge. The reliable approach: create tables with plain SQL you've validated, then use Prisma purely as a runtime client over the existing schema. Treat unsupported syntax as the boundary — never a silent mis-parse. Surface growth is tracked on the roadmap (Phase 6).

# 1) Create schema out-of-band (psql or any client)
psql "postgresql://[email protected]:5433/main?sslmode=disable" \
  -c "CREATE TABLE IF NOT EXISTS \"Note\" (id INTEGER PRIMARY KEY, body TEXT NOT NULL, ts TEXT NOT NULL)"

# 2) Generate the client only (no migrate)
npx prisma generate

Breakdown: match the table/column names to your Prisma models (Prisma quotes "Note" by default). prisma generate builds the typed client without touching the database, so you skip the migration engine entirely.

Next

Twill DB documentation · Licensed under BUSL-1.1. · Author