LynAPI, database and auth. One install.
A Bun backend that comes already wired. No ORM to set up, no pool to create, no middleware to glue. Install it and write your routes.
A Bun backend that comes already wired. No ORM to set up, no pool to create, no middleware to glue. Install it and write your routes.
1. Install
bun add @rouret/lyn2. Point it at Postgres
# .env
DATABASE_URL=postgres://localhost:5432/app3. Write your routes
import { Lyn, z } from "@rouret/lyn";
import * as schema from "./db/schema";
await new Lyn({ database: { schema } })
.get("/users", ({ db }) => db.query.users.findMany())
.post(
"/users",
async ({ db, body }) => {
const [user] = await db.insert(schema.users).values(body).returning();
return user;
},
{ body: z.object({ email: z.email(), name: z.string() }) }
)
.listen(3000);That's the whole app. The connection is checked at startup, db is typed from your tables, invalid bodies get a 400.
| Usually | With Lyn |
|---|---|
| Install an ORM, a driver, and create a connection pool | Pass your schema |
Make db available in every handler | It's in the context |
| Check the database is reachable before serving | Done by listen() |
| Validate env variables, and find a missing one in production | Checked and typed at startup |
| Write a validation middleware and type the request by hand | Zod schemas, types inferred |
| Write an error handler, and avoid leaking stack traces | One JSON error format, nothing leaks |
| Set up request logging and request ids | One line per request, built in |
| Pick, install and wire an auth library | Built in, coming next |
Sign-up, sign-in and sessions, stored in the same Postgres database, with nothing to install or configure. It is the next feature on the roadmap.
db can do.