Database

Also called DB or SQL database

An organized store for your app's data, such as users, posts, or orders, kept in tables so the app can save, find, and update it.

What is Database?

A database keeps data after the page closes. Most apps use a relational database such as PostgreSQL or SQLite, which stores data in tables: each table holds one kind of thing, each row is one record, and each column is one field, like name or created_at.

When someone adds a habit, the backend inserts a row into the habits table. When the list loads, it reads the rows back. The layout of the tables is called the schema, and changes to it are made with migrations.

Ask the AI to describe the tables before it builds features on top of them, since a schema is harder to change once real data exists. Back up production data, and make sure each user can read and change only their own rows.

Common errors

New row violates row-level security policy
Postgres refused to save a row because no row-level security policy on that table lets the current user write it.
Relation does not exist
The query names a table that Postgres can’t find in this database, usually because it was never created here or has a different name.
Duplicate key value violates unique constraint
The app tried to save a row whose ID, email, or other unique value is already in the table, so Postgres rejected the copy.
All terms

Frontend and backend

The two halves of a web app: the frontend runs in the browser and draws what you see, and the backend runs on a server and handles data.

API

A set of rules that lets one program ask another for data or actions, usually by sending a request to a URL and getting JSON back.

Data table

A table built for working with records: click a column header to sort, type to filter, and check rows to act on several at once.

Optimistic UI

A pattern where the interface shows the result of an action right away, before the server confirms it, and rolls it back if the request fails.