← 输入框|dbcode.io|刷新
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.

Run DBCode: Uninstall CLI from the command palette, or dbcode uninstall from a terminal. Either removes the link that install created (on Windows, the folder and its PATH entry too). Uninstalling the DBCode extension removes the link as well.

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

In a VS Code window connected to a Dev Container, an SSH host or WSL, dbcode query runs in that window’s terminals, and in scripts, notebooks and debug sessions started there. DBCode in that window runs the SQL on the connections it shows. Run DBCode: Install CLI in that window to put dbcode on its path.

  • Output formats and exit codes are the same as in any other terminal.
  • --database, --schema, --limit and --no-limit work as usual. --timeout counts the whole wait, including a confirmation prompt in VS Code. Ctrl+C cancels the running query.
  • The query runs on the connection the editor already has open for that database, so a USE or SET in a script also applies in the editor, and the connection stays open in the explorer.
  • A statement your environment role marks “ask” shows its confirmation in VS Code. --yes approves it, as in any other terminal.
  • --app, --profile and --workspace read the settings files on the container or remote host instead.

If the CLI reports that DBCode is not running in the window, open the DBCode view or reload the window. dbcode connections, dbcode open and dbcode introspect work there too.

The CLI follows the editor’s telemetry.telemetryLevel and dbcode.disableOnlineServices settings. It reads the editor’s secret store only for the password of the connection you use and, for dbcode mcp, the stored licence. It never writes to it and never prints a secret.

DBCODE_DEBUG=1 writes diagnostics to stderr, including raw driver errors. Leave it off unless you are diagnosing a problem.