@sushindustries/db

0.1.0

The schema and the client. Drizzle over Postgres, with the connection kept server-side by construction.

pnpm add @sushindustries/db
1 min read
View as Markdown

The schema and the client. Drizzle over Postgres, with the connection kept server-side by construction.

Install

pnpm add @sushindustries/db
shell

Two entry points, on purpose

// Safe anywhere. Table shapes and inferred types, no driver.
import { packageStats, type PackageStat } from "@sushindustries/db/schema";

// Server only. Reads DATABASE_URL and opens a connection.
import { getDb } from "@sushindustries/db/client";
ts

The split is the whole design. schema carries types a form or a table needs, so a component can import them without pulling a Postgres client into the browser bundle. client.server.ts carries the connection, and its .server.ts suffix is in TanStack Start's default client deny list - importing it from client-reachable code is a build error, not a code review note.

Migrations

export DATABASE_URL=postgres://...
pnpm db:generate   # write SQL from the schema
pnpm db:migrate    # apply it
pnpm db:studio     # browse it
shell

Why the connection is lazy

Railway injects DATABASE_URL at runtime, not at build time. A module-scope connection would be constructed during the build with an undefined URL and take down the whole deploy, instead of failing the one route that actually needs a database.