Skip to content

SQL Terminal ​

Run SQL against a config's database from the shell or the TUI, with every statement checked against the config's role first.

bash
noorm sql query "SELECT party_id, order_no, status FROM sales_order ORDER BY 1, 2"
Columns: party_id, order_no, status
{"party_id":1,"order_no":1,"status":"paid"}
{"party_id":2,"order_no":1,"status":"invoiced"}
{"party_id":2,"order_no":2,"status":"open"}
3 rows returned (2ms)

Shift+Q on any TUI screen opens the active config in an interactive terminal with a results grid and saved history. From a shell, run noorm sql repl --config dev, which needs a TTY and exits with a usage error under --yes or NOORM_YES. noorm sql covers query, including -f file.sql and --json.

What am I allowed to run? ​

The text is parsed and classified before anything reaches the database. The highest class wins:

ClassStatementsvieweroperatoradmin
sql:readSELECT, VALUES, TABLE, an EXPLAIN of a read, SHOW and DESCRIBE on MySQLyesyesyes
sql:writeINSERT, UPDATE, DELETE, MERGEnoyesyes
sql:ddleverything else: CREATE, ALTER, DROP, TRUNCATE, GRANT, SET, CALL, EXEC, and input no keyword matchesnonoyes

src/core/policy/classify.ts decides these cases:

Input (PostgreSQL)ClassWhy
WITH gone AS (DELETE FROM order_line RETURNING *) SELECT * FROM gonesql:writea DELETE inside the WITH
EXPLAIN ANALYZE DELETE FROM order_linesql:writeEXPLAIN takes the class of what it runs
SELECT * INTO order_copy FROM sales_ordersql:ddlit creates a table
SELECT pg_terminate_backend(pid) FROM pg_stat_activitysql:writea side-effecting builtin on the denylist

The denylist names known-dangerous builtins, such as nextval and pg_read_file. It stops accidental writes on a viewer config and is not a sandbox.

How do I work in the terminal? ​

WhereKeys
Query inputEnter runs, Shift+Enter adds a line. Shift+Tab toggles edit mode ([EDIT]>), where Enter adds a line. Tab inserts four spaces. ↑ ↓ recall earlier queries and h opens history, both on an empty input
Results grid↑ ↓ move. Enter opens the row as YAML or JSON (← → change row, f switches format). / filters, s sorts, c clears both
Between themA query that returns rows opens the grid. Tab or Esc returns to the query
Any timeEsc stops a running query or connect, otherwise clears the input, and on an empty input leaves

A statement without rows shows ✓ 1 row(s) affected (5ms) or ✓ Query executed (42ms). A failure shows ✗ and the server's message.

How do I stop a query? ​

Esc returns the terminal to you. Whether the server stops working depends on the dialect:

DialectOn Esc
PostgreSQLpg_cancel_backend on a second connection
MySQLKILL QUERY on a second connection
SQL Servernothing reaches the server
SQLitenothing reaches the server

The first two show Cancelled. The server was asked to stop the query. The last two show Stopped waiting. The query may still be running on the server. There the query may keep running and holding its locks, so kill it server-side if that matters.

Where does history go? ​

Only the interactive terminal records history, one file set per config. sql query records nothing. A statement the role refused is recorded as a failure.

bash
noorm sql history -n 2
SQL history for 'dev' (2 entries):

  ✓  Oct 21 at 01:42:51  5ms · 1 row(s)
     UPDATE sales_order SET status = 'paid' WHERE party_id = 2 AND order_no = 1

  ✗  Oct 21 at 01:42:51  2ms · relation "sale_order" does not exist
     SELECT * FROM sale_order

In the TUI, h opens the same list. r sends the selected query back to the input, Enter opens its stored rows or error, and c opens the clear menu. From a shell: noorm sql clear --older-than 3 --yes.

History is not encrypted

Query text sits in .noorm/state/history/<config>.json and returned rows sit gzipped in .noorm/state/history/<config>/. Both are owner-only (0600, in a 0700 directory), but anything a SELECT pulled from a credentials or PII table is readable by your user account. Clear the history after a sensitive query.

What bites ​

SymptomCauseFix
"sql:write" is not allowed on config "ro" (role: viewer).The class needs a higher role than your channel has. In an agent session the channel is agent, which defaults to viewerRaise the role, or see channels
SHOW search_path (PostgreSQL) or PRAGMA … (SQLite) is refused below adminBoth parse as statements the classifier does not list as reads, so they count as sql:ddlSELECT current_setting('search_path'), or SELECT * FROM pragma_table_info('sales_order')
noorm sql -f reports/monthly.sql prints Unknown commandThe bare form needs the SQL as the first token after sqlnoorm sql query -f reports/monthly.sql
noorm sql history is empty after you ran queriesThey ran through sql queryRun them in the terminal

Next ​