Database

Database

Built-in PostgreSQL

Every project gets a dedicated PostgreSQL database with its own schema. Access it from the DB button in the IDE footer. Your database credentials are stored securely as server-side secrets — they are never committed to your git repository.

  • Dedicated PostgreSQL schema per project (e.g. proj_abc123)
  • Connection URL and REST API URL available in the DB panel
  • The AI assistant can write SQL queries and schema changes via the <sql> tag

Tables & data

The DB panel has four tabs for managing your data:

  • Data — browse rows with pagination (50 per page), edit cells inline by clicking, insert new rows, delete rows
  • Schema — view column definitions (type, nullable, default, primary key), add or delete columns
  • SQL — run raw SQL queries; results shown in a table with row count
  • Access — configure row-level access policies per table (see below)

Supported column types: TEXT, INTEGER, BIGINT, SERIAL, BOOLEAN, FLOAT, NUMERIC, TIMESTAMPTZ, DATE, JSON, JSONB, UUID, VARCHAR(255).

Your schema name, REST URL, ANON key, and API key are always visible in the bottom-left of the DB panel for quick copy-paste.

SQL console

The SQL tab lets you run raw SQL queries against your project's database. Results are shown in a table with row count. Errors are displayed inline.

NoteAll queries run within your project's schema — you never need to prefix table names. Cross-schema references are blocked for security.

REST API & Access Control

Every project database is accessible via a REST API at https://api.aicodesit.com/db/{id}/rest/{table}. Three auth levels control what each request can do:

  • ANON_KEY (apikey: ANON_KEY header) — public access, respects the table's Access policy
  • DB_API_KEY (Authorization: Bearer dak_…) — admin access, bypasses all access policies
  • Session token (Authorization: Bearer <token>) — logged-in user, enables row-ownership policies

Configure each table's access rules from the Access tab in the DB panel:

  • Public read (anon_select) — anyone with your ANON_KEY can read rows (e.g. blog posts, product listings)
  • Public write (anon_insert) — anyone can insert rows without logging in (e.g. contact forms, newsletter signups)
  • Logged-in Insert — only logged-in users can insert rows on by default
  • Logged-in Read Own (auth_select_own) — users only see rows they own, filtered by user_id_col. Prevents users from reading each other's data on by default
  • Logged-in Update Own / Delete Own — users can only edit or delete rows they created (matched by user_id_col) on by default
NoteNew tables are created with secure defaults: anonymous access is blocked, and logged-in users can only read, update, and delete their own rows. Users with role=admin bypass row-ownership filters and can access all rows.

Real-time row streaming is available at https://api.aicodesit.com/db/{id}/rest/{table}/stream?apikey=ANON_KEY using Server-Sent Events. The AI uses this endpoint when building live-updating UIs.