Tables

Create and manage database tables from the CLI. Each table automatically gets REST API endpoints.

Create a table

terminal
based table create <name> <columns...>

# Example
based table create posts \
  title:text:required \
  content:text \
  status:text:default=draft \
  author_id:integer:ref=users.id

Column syntax

Each column is defined as name:type[:modifier...] where modifiers are optional and can be chained.

ModifierExampleDescription
requiredtitle:text:requiredColumn cannot be null
uniqueslug:text:uniqueValues must be unique
default=valuestatus:text:default=draftDefault value when omitted
ref=table.columnauthor_id:integer:ref=users.idForeign key reference

Column types

TypeDescription
textUTF-8 string
integer64-bit signed integer
real64-bit floating point
blobBinary 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.

terminal
based table create notes \
  user_id:text:required \
  title:text:required \
  body:text

See the REST API → Row-level scoping section for details.

Add columns

terminal
based table add-column <table> <columns...>

# Example
based table add-column posts \
  likes:integer:default=0 \
  published_at:text

Drop columns

terminal
based table drop-column <table> <columns...>

# Example
based table drop-column posts likes published_at

Drop a table

terminal
based table drop <name>

# Example
based table drop posts

This permanently deletes the table and all its data. There is no undo.

List tables

terminal
based table list

Generate 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.

terminal
based typegen

See the SDK docs for details on using the generated types with useQuery and useMutation.