// COMPLETE REFERENCE

Database

Chapter 642 3 min read English Stable reference URL
Database Interface Screen

A schema browser, data grid and SQL console for the bot’s PostgreSQL database, inside the suite. It is a developer tool (registry category: "dev") used to inspect tables while building a bot, not a task an office user performs — hence this reference chapter instead of the app guide.

Authority: botui/ui/suite/database/ (database.html plus modules/01_state.js … 04_actions.js), botserver/crates/botdatabase/src/ (routes, handlers, SQL policy), and entries_extra.rs:106-115.

The screen

Region What it does
Schema browser table list with a text filter, refresh, and + New Table
Grid / Fields view tabs the row grid, or a per-column field view
Data grid paginated (Previous / Next), selectable rows, delete selected, inline cell editing
SQL console free SQL with Execute (Ctrl+Enter) and an EXPLAIN button that prefixes EXPLAIN ANALYZE
Export downloads the current table as CSV
Import uploads a CSV file into the current table

CSV import and export

Export fetches /api/database/table/{name}/export?format=csv, receives a blob and triggers a download; it cannot use window.open because the bearer token is injected by the fetch wrapper, not by the browser.

Import is client-side and deliberately simple (04_actions.js:312-345): the file is split on newlines and commas, the first line is taken as the header, and every remaining line becomes one POST .../row. Quoted commas, embedded newlines and type conversion are not handled — for anything beyond a clean comma-separated file, insert through the SQL console or a script.

SQL policy

POST /api/database/query is a single-statement runner with a real token classifier (botdatabase/src/handlers/sql_policy/), and it is enforced twice — by the policy and by PostgreSQL, because every read executes inside BEGIN TRANSACTION READ ONLY.

Statement Outcome
A single read (SELECT, EXPLAIN of a read, SHOW) runs read-only
A single plain DML (INSERT, UPDATE, DELETE, MERGE) runs through the administrator-only write path
WITH … (DELETE/UPDATE …), EXPLAIN ANALYZE <dml>, SELECT … FOR UPDATE, SELECT … INTO refused
DDL, DCL, COPY, transaction control, multiple statements refused
pg_read_file/pg_write_file/pg_ls_dir/dblink and the credential catalogues (pg_authid, pg_shadow) refused

DDL has its own routes (POST /table, PUT|DELETE /table/{name}, POST /table/{name}/column), and those are administrator-only in the RBAC table (routes_admin_database.rs:22-32) — as is POST /api/database/query itself (handlers/query_admin.rs). Reads of table data are available to authenticated callers.

HTTP surface

Method Path
GET /api/database/schema
GET /api/database/table/{name}/data?page=&page_size=
GET /api/database/table/{name}/foreign-keys
GET /api/database/table/{name}/export?format=csv
POST /api/database/query
POST /api/database/table · PUT/DELETE /api/database/table/{name} · POST /api/database/table/{name}/column
POST /api/database/table/{name}/row · PUT /api/database/table/{name}/row · PUT/DELETE /api/database/table/{name}/row/{id}
POST /api/database/table/{name}/rows/batch-delete

Every route is in botdatabase/src/routes.rs:11-21 and in the generated api-database.

Not implemented

Claim that appears elsewhere Reality
Saved queries and query history no route and no UI for either
JSON/CSV API envelopes (/tables, /tables/:name/rows, /import/csv) the routes above are the whole surface
Syntax highlighting and auto-complete in the SQL console the textarea is plain; EXPLAIN is the only helper
// SEARCH ESC
Pagefind · 236 pages · 4 books Enter to open ↑ ↓ to move