Skip to content

CLI

Command Line

The dbcode command runs queries against the connections you already saved in DBCode. It reads the same settings files your editor does, so there is nothing to configure twice.

  1. Run DBCode: Install CLI from the command palette. It links dbcode into a folder on your PATH (/usr/local/bin, ~/.local/bin or ~/bin on macOS and Linux; %LOCALAPPDATA%\Programs\dbcode on Windows, which is added to your user PATH).
  2. Open a new terminal and run dbcode --version.

The CLI runs under the Node.js on your PATH and needs Node 22.14 or newer. Extension updates keep the link pointing at the current version.

Terminal window
dbcode connections
dbcode query -c "My Postgres" "select now()"

-c takes a connection name, or its id when two connections share a name. SQL comes from the argument, from --file, or from stdin:

Terminal window
cat report.sql | dbcode query -c warehouse --format csv > report.csv

SQL that starts with a -- comment must follow a literal -- so the argument parser does not read it as a flag:

Terminal window
dbcode query -c prod -- "-- daily count
select count(*) from orders"
FormatWhen
tableDefault on a terminal
jsonDefault when piped. One array of row objects per result set
jsonlOne object per line
csv, tsvByte-identical to the grid’s Export
markdownFor pasting into docs and chat

Only data goes to stdout. Status lines (INSERT 2), the row-limit notice and errors go to stderr.

FlagMeaning
--database, --schemaOverride the connection’s defaults for this run
--limit N, --no-limitRow cap. Defaults to the dbcode.queryRowLimit setting
--timeout SRequest timeout in seconds
-y, --yesApprove statements your environment role marks as “ask”
--app, --profile, --workspaceWhich editor, profile and workspace folder supply the settings
CodeMeaning
0Success, including truncated results
1The database returned an error
2Usage error, unknown connection, unsupported connection
3Could not connect or authenticate
4Refused by your environment role, or you answered no
130Interrupted