---
title: "Database: Postgres tables, REST API and RLS | Backenly Docs"
description: "The Database section: PostgreSQL tables your coding agent creates, a REST API for every table, row-level security, and how schema changes apply and roll back."
url: https://backenly.com/docs/database
markdown_url: https://backenly.com/docs/database.md
updated: 2026-10-12
---

# Database

Database holds your app’s data in PostgreSQL tables: posts, orders, messages, anything your app needs to remember. Every table is served as a REST API the moment it exists, and row-level security decides which rows each signed-in user can read and change.

In the console: Build › Database · Build · Updated October 12, 2026

## Why you need it

Almost every app has to remember things between visits: who ordered what, which tasks are done, what a user wrote. That is the database. On Backenly you do not write the server code that usually sits in front of it. Your agent creates the tables, Backenly serves them as an API, and the access rules run inside PostgreSQL, so a filter forgotten on one screen cannot show one user another user’s data.

For example:

- A task app stores projects and the tasks inside them, and each user sees only their own.
- A shop stores products, orders and order items, linked by foreign keys.
- A chat app stores conversations and messages that only the two people in the conversation can read.
- You answer a question about your data with a read-only SQL query, which cannot change anything.

## How it works

1. **Your agent asks for the change.** With ordinary PostgreSQL DDL through `apply_migration`, or by describing the tables to `backend_chat`. Either way, Backenly translates the request into its own fixed set of actions instead of running the SQL as written, and refuses anything it cannot translate.
2. **Backenly applies the checked steps.** Tables are created in your project’s own PostgreSQL schema, with a schema snapshot before a change. A multi-statement migration is checked before any step runs; if execution fails, it stops and reports what applied and what remains, so your agent can finish without replaying completed work.
3. **Every table gets an API.** `/api/v1/{projectId}/db/{table}` lists, creates, reads, updates and deletes rows, with filters, sorting and pagination. There is no generate step and nothing to keep in sync.
4. **The rules run in the database.** Row-level security policies read the signed-in user from each request, so the same rule holds through the REST API and the SDK. After a build, Backenly signs in a second test user and checks they cannot read the first user’s rows.

## Try it

Ask your agent:

```text
Create a tasks table with a title, a status of todo, in_progress or done, and a due date. Each user can only see and edit their own tasks.
```

```text
Add a comments table. Each task has many comments, and each comment belongs to the user who wrote it.
```

From your app:

```js
import { createClient } from '@backenly/sdk'

const backend = createClient({ projectId, apiKey })

const open = await backend.tasks.list({ where: { status: 'todo' }, limit: 25 })
await backend.tasks.create({ title: 'Ship onboarding', status: 'todo' })
```

## Good to know

- A request without a signed-in user’s token reads zero rows from a protected table instead of failing. If a list is unexpectedly empty, check the `X-User-Token` header before the data.
- Every table Backenly creates gets `id`, `"createdAt"`, `"updatedAt"` and `deleted_at`. Rows with a `deleted_at` time are left out of API reads unless the request asks for `include_deleted=true`.
- Dropping a table or a column never runs straight from your agent. It waits in the [Autonomy](https://backenly.com/docs/autonomy) review queue until a person approves it.
- There is no `rpc()` endpoint for SQL functions. Server-side logic runs as a [Function](https://backenly.com/docs/functions).

Next: [Auth & Users](https://backenly.com/docs/auth.md)

---

Source: [Database: Postgres tables, REST API and RLS | Backenly Docs](https://backenly.com/docs/database). Every page in Markdown: https://backenly.com/index.md. Agent docs: https://backenly.com/llms.txt.
