Sypnorm
The use-case ORM that comes with Cases. Your code is a set of use cases, and the map comes from it.
On this page
Most ORMs organize code around tables. Sypnorm organizes it around what people do: use cases. «A customer orders today’s bread» is one use case: it says who does it, what it receives, which tables it reads and writes, and every way it can fail. Your app is the set of its use cases, and Sypnorm derives that set as the code side of your map.
That is why Sypnorm belongs to Cases. A Cases map written by people says what the app must do; Sypnorm says, from the code itself, what the app does. The check compares the two.
How to write a use case with Sypnorm, what each part means, and how failures work.
Generate typed tables from your database, and read and write with Sypnorm's query builder.
Run use cases on Sypnia Data through its API, or on any Postgres with a direct connection, all or nothing.
Derive the map from your use cases, upload it to your Cases project, and keep code and map in agreement.
One package
npm install @sypnia/cases| Import | For |
|---|---|
@sypnia/cases/sypnorm | the ORM: useCase, ctx.db, ctx.outcome, typed tables, runners and transactions |
@sypnia/cases/map | derive the map from your code and upload it, from your own scripts |
@sypnia/cases/spec | the format: types, JSON Schemas, parser and validator (The SDK) |
@sypnia/cases/client | the Cases API (The SDK) |
The command comes with it: npx @sypnia/cases generate, tables, map, link, check and the rest of the CLI.
Where it runs
| Database | Runner | Transactions |
|---|---|---|
| Sypnia Data | through the Data API, with the person’s token, under row-level security, for cases nobody listens to; a case some case listens to runs in its area’s service | atomic over HTTP, one request per use case (Runners) |
| Any Postgres 14+ | a direct connection from your server | real Postgres transactions, with row locks |
Sypnorm does not need Sypnia Data, and Sypnia Data does not need Sypnorm: Data works with plain SQL, Prisma, Drizzle or any other tool.
Why use cases
- Anyone can read the app. A use case reads like the sentence a client would say.
- Scope is visible. The map lists everything the app does; a flow that is not on it is a scope error.
- Every ending is part of the design. Outcomes and failures are named and typed in the case file, and
ctx.outcomeaccepts nothing else, so nothing is found by surprise in production. - Production by use case. With Sypnia Telemetry, each run is a span named after its use case, with its outcome; when another case listens, the area’s service saves the outcome in the outbox in the same transaction (Running cases).