Node.js / TypeScript: Prisma
Applies a Prisma migration (_prisma_migrations, advisory locks, introspection), then creates and counts rows through the generated client. The code is the same against the original database and against MachSQL; only the address changes.
The only change
Section titled “The only change”DATABASE_URL=postgresql://app:${DB_PASSWORD}@old-postgres:5432/appDATABASE_URL=postgresql://app:${DB_PASSWORD}@machsql-host:5432/appNothing else changes: not the code, not the driver, not its version, not the SQL.
Versions
Section titled “Versions”- Node.js 26 LTS
- Prisma 7.10.1 with @prisma/adapter-pg 7.10.1
- TypeScript 7.0.2, tsx 4.23.15
npm installexport DATABASE_URL=postgresql://app:${DB_PASSWORD}@machsql-host:5432/appnpm run migratenpm run generatenpm startExpected output: inserted todo <id>, <n> open.
Source
Section titled “Source”The program as it is kept and tested in the Mach Database for PostgreSQL repository; highlighted lines read the connection setting.
import { defineConfig, env } from "prisma/config";
export default defineConfig({ schema: "prisma/schema.prisma", migrations: { path: "prisma/migrations" }, datasource: { url: env("DATABASE_URL") },});// Prisma ORM with the pg driver adapter.import { PrismaPg } from "@prisma/adapter-pg";import { PrismaClient } from "./generated/prisma/client.js";
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });const prisma = new PrismaClient({ adapter });
try { const todo = await prisma.todo.create({ data: { title: "write the examples" } }); const open = await prisma.todo.count({ where: { done: false } }); console.log(`inserted todo ${todo.id}, ${open} open`);} finally { await prisma.$disconnect();}node_modules/src/generated/{ "name": "machsql-example-node-prisma", "private": true, "type": "module", "scripts": { "migrate": "prisma migrate deploy", "generate": "prisma generate", "start": "tsx src/index.ts" }, "dependencies": { "@prisma/adapter-pg": "7.10.1", "@prisma/client": "7.10.1" }, "devDependencies": { "@types/node": "26.6.6", "prisma": "7.10.1", "tsx": "4.23.15", "typescript": "7.0.2" }}CREATE TABLE "prisma_todo" ( "id" BIGSERIAL NOT NULL, "title" TEXT NOT NULL, "done" BOOLEAN NOT NULL DEFAULT false, CONSTRAINT "prisma_todo_pkey" PRIMARY KEY ("id"));provider = "postgresql"generator client { provider = "prisma-client" output = "../src/generated/prisma"}
datasource db { provider = "postgresql"}
model Todo { id BigInt @id @default(autoincrement()) title String done Boolean @default(false)
@@map("prisma_todo")}