# Use any ORM

> Sypnia Data is plain Postgres. Use plain SQL, Prisma, Drizzle, Sypnorm or nothing at all, and mix them.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://data.docs.sypnia.com/data/any-orm/

For agents: Sypnia Data is the data layer (auth, tables, Data API, SQL, row-level security, MCP) and has no ORM of its own. Options on the same tables: @sypnia/data/client (Data API with the person's token, under RLS), plain SQL (/sql/v1 or a direct connection), Prisma or Drizzle (direct connection: your own Postgres or a dedicated database; managed shared has none; migrations through their tools or npx @sypnia/data migrate), Sypnorm (the use-case ORM, part of Sypnia Cases: @sypnia/cases/sypnorm, runs through the Data API or a direct connection; a case other cases listen to runs in its area's service, POST /_cases/<id>; https://cases.docs.sypnia.com/sypnorm/). Through a direct connection, row-level security applies only if you set the role (SET LOCAL ROLE authenticated + request.jwt.claims).

Sypnia Data is the **data layer**: sign-in, tables, the Data API, SQL, row-level security and MCP. Your tables are ordinary Postgres tables, so the way you write your app is yours to choose. You can mix several on the same project.

| Option                    | Talks to Sypnia Data through                                                                                                                                          | Good for                                                                                               |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| **`@sypnia/data/client`** | the [Data API](https://data.docs.sypnia.com/data/rest-api), with the person's token, under [row-level security](https://data.docs.sypnia.com/data/row-level-security) | apps in a browser or a phone, with no server of your own                                               |
| **Plain SQL**             | [`/sql/v1`](https://data.docs.sypnia.com/data/sql-and-migrations) with a secret key, or a direct connection                                                           | servers, reports, migrations                                                                           |
| **Prisma**                | a direct connection                                                                                                                                                   | teams that already use it                                                                              |
| **Drizzle**               | a direct connection                                                                                                                                                   | typed SQL close to the database                                                                        |
| **Sypnorm**               | the Data API or a direct connection                                                                                                                                   | writing the app as **use cases**; it comes with [Sypnia Cases](https://cases.docs.sypnia.com/sypnorm/) |

## Plain SQL

```ts
import { createClient } from '@sypnia/data/server';
const admin = createClient('https://<ref>.data.sypnia.com', { secretKey: process.env.SYPNIA_SECRET_KEY! });
const rows = await admin.sql`select id, total from orders where status = ${'paid'}`;
```

## Prisma or Drizzle

They need a direct connection: your own Postgres, or a dedicated database in Sypnia Cloud ([Projects and databases](https://data.docs.sypnia.com/cloud/projects-and-databases)). Managed shared databases have no direct connection; there, use the Data API or SQL. Put the connection string in `DATABASE_URL` and use the tool as you would on any Postgres ([Any Postgres](https://data.docs.sypnia.com/data/any-postgres)).

```bash
DATABASE_URL="postgres://<user>:<password>@<host>:5432/postgres" npx prisma db pull
```

Migrations can stay with your tool, or go through `npx @sypnia/data migrate` ([SQL and migrations](https://data.docs.sypnia.com/data/sql-and-migrations)); pick one so the history lives in one place.

> **Warning: Row-level security and direct connections**
>
> A direct connection runs as the user you connect with, and that user usually skips row-level security. If a server acts for a person, set the role first (`set local role authenticated` and `request.jwt.claims`), or use the Data API with the person's token.

## Sypnorm, with Cases

**Sypnorm** is the ORM where your app is a set of use cases: who does what, with which tables, and how it can fail. It belongs to **Sypnia Cases**, because the use cases it derives are the code side of your Cases map. It runs on Sypnia Data, through the Data API with each person's token or with a direct connection, and on any other Postgres. A case some other case listens to runs in its area's service, which the app calls with the person's session, so its event is saved with its data ([Runners](https://cases.docs.sypnia.com/sypnorm/runners/)).
