Skip to content

Query File Sessions

Query files are the best current CLI surface for multi-statement workflows.

-- tonic-file: target=warehouse context.schema=public autocommit=off
update accounts set plan = 'pro' where id = 1;
select id, plan from accounts where id = 1;
commit;

Run it:

Terminal window
tonic query exec --file account-upgrade.sql

All three statements use the primary reusable session. With autocommit=off, ordinary statements participate in the same transaction until commit or rollback.

-- tonic-bind: handle=writer target=warehouse context.schema=public autocommit=off
-- tonic-bind: handle=reader target=warehouse context.schema=analytics autocommit=on
-- tonic: handle=writer
update reports.job_state set last_run_at = current_timestamp where name = 'daily_sales';
-- tonic: handle=reader
select count(*) as rows_seen from daily_sales;
-- tonic: handle=writer
commit;

The writer and reader use separate reusable sessions because they have different handles and context.

-- tonic-file: target=warehouse context.schema=analytics
select count(*) from daily_sales;
-- tonic: target=scratch
select sqlite_version();

The second statement is ephemeral. It opens a one-off session and closes it immediately after execution.