Tables
Create and manage database tables from the CLI. Each table automatically gets REST API endpoints.
Create a table
based table create <name> <columns...>
# Example
based table create posts \
title:text:required \
content:text \
status:text:default=draft \
author_id:integer:ref=users.idColumn syntax
Each column is defined as name:type[:modifier...] where modifiers are optional and can be chained.
| Modifier | Example | Description |
|---|---|---|
| required | title:text:required | Column cannot be null |
| unique | slug:text:unique | Values must be unique |
| default=value | status:text:default=draft | Default value when omitted |
| ref=table.column | author_id:integer:ref=users.id | Foreign key reference |
Column types
| Type | Description |
|---|---|
| text | UTF-8 string |
| integer | 64-bit signed integer |
| real | 64-bit floating point |
| blob | Binary data |
Auto-added columns
Every table automatically includes id (primary key), created_at, and updated_at. You do not need to define these.
Per-user isolation
Add a user_id column (or userId) to automatically scope the table to the authenticated user — no policy language needed. The REST API enforces the filter on reads, forces ownership on writes, and rejects anon access.
based table create notes \
user_id:text:required \
title:text:required \
body:textSee the REST API → Row-level scoping section for details.
Add columns
based table add-column <table> <columns...>
# Example
based table add-column posts \
likes:integer:default=0 \
published_at:textDrop columns
based table drop-column <table> <columns...>
# Example
based table drop-column posts likes published_atDrop a table
based table drop <name>
# Example
based table drop postsThis permanently deletes the table and all its data. There is no undo.
List tables
based table listGenerate types
After creating or modifying tables, run based typegen to regenerate your TypeScript interfaces. This keeps your SDK types in sync with the database schema.
based typegenSee the SDK docs for details on using the generated types with useQuery and useMutation.