This repository shows a W7S JavaScript/TypeScript native backend using the W7S serverless database path: a D1 SQL binding with Drizzle ORM.
The app exposes a tiny notes API:
GET /api/healthchecks the backend and binding shape.GET /api/noteslists the latest notes from D1.POST /api/notescreates a note with Drizzle.
w7s.jsondeclares theDBD1 binding and points W7S at themigrations/directory.migrations/0001_create_notes.sqlcreates thenotestable.migrations/0002_seed_notes.sqlinserts one starter row.backend/src/schema.tsdefines the Drizzle schema.backend/src/index.tsusesdrizzle(env.DB)fromdrizzle-orm/d1..github/workflows/deploy.ymlbuilds, deploys, and smoke-tests the database.
{
"bindings": {
"d1": [
{
"binding": "DB",
"migrations": "migrations"
}
]
}
}W7S creates one database for the repository and environment, applies sorted SQL migrations, and exposes the binding to the backend as env.DB.
import { drizzle } from "drizzle-orm/d1";
import { notes } from "./schema";
const db = drizzle(env.DB);
const rows = await db.select().from(notes);npm install
npm run check
npm run db:generatenpm run db:generate uses Drizzle Kit to generate SQL from backend/src/schema.ts. The checked-in migrations are plain SQL so W7S can apply them during deploy.
Push to GitHub. The workflow runs npm run check and deploys with:
- uses: w7s-io/w7s-cloud@v1
with:
token: ${{ github.token }}The deployed app is served at:
https://w7s-io.w7s.cloud/example-serverless-database/