Skip to content

Repository files navigation

fb-cli

Firebolt CLI; work with Firebolt and Firebolt Core.

Examples

➤ fb select 42
?column?
---------
42
Time: 41.051ms

REPL

➤ fb
=> select 42
?column?
---------
42
Time: 40.117ms
=> create table t (a int);
Table 't' already exists.
Time: 87.747ms
=> insert into t select * from generate_series(1, 100000000);
/

Also support history + search in it (CTRL+R).

Help

➤ fb --help
Usage: fb [OPTIONS]
Positional arguments:
query Query command(s) to execute. If not specified, starts the REPL
Optional arguments:
-c, --command COMMAND Run a single command and exit
-C, --core Preset of settings to connect to Firebolt Core
-h, --host HOSTNAME Hostname (and port) to connect to
-d, --database DATABASE Database name to use
-f, --format FORMAT Output format (e.g., TabSeparatedWithNames, PSQL, JSONLines_Compact, Vertical, ...)
-e, --extra EXTRA Extra settings in the form --extra <name>=<value>
-l, --label LABEL Query label for tracking or identification
-j, --jwt JWT JWT for authentication
--sa-id SA-ID Service Account ID for OAuth authentication
--sa-secret SA-SECRET Service Account Secret for OAuth authentication
--jwt-from-file Load JWT from file (~/.firebolt/jwt)
--oauth-env OAUTH-ENV OAuth environment to use (e.g., 'app' or 'staging'). Used for Service Account authentication (default: staging)
-v, --verbose Enable extra verbose output
--concise Suppress time statistics in output
--hide-pii Hide URLs that may contain PII in query parameters
--no-spinner Disable the spinner in CLI output
--update-defaults Update default configuration values
-V, --version Print version
--help Show help message and exit

Install

Precompiled binaries (recommended)

The easiest way to install fb is to download a release binary from GitHub Releases.

  1. Open the latest release and download the asset that matches your OS and CPU:

    AssetPlatform
    fb-linux-static-amd64Linux amd64 (Intel/AMD 64-bit)
    fb-linux-static-arm64Linux arm64
    fb-darwin-amd64macOS Intel (amd64)
    fb-darwin-arm64macOS Apple Silicon (arm64)
  2. Make it executable and install it as fb on your PATH (use the exact filename you downloaded):

    chmod +x ./fb-linux-static-amd64
    sudo mv ./fb-linux-static-amd64 /usr/local/bin/fb

    Or install to your user directory (no sudo):

    mkdir -p ~/.local/bin
    chmod +x ./fb-linux-static-amd64
    mv ./fb-linux-static-amd64 ~/.local/bin/fb

    Ensure ~/.local/bin is on your PATH (e.g. in ~/.bashrc or ~/.zshrc).

  3. Run fb --version to confirm.

Build from source (alternative)

Use this if you prefer to compile locally or need a platform not covered by release binaries.

  1. Install Rust and cargo. Add source "$HOME/.cargo/env" to ~/.bashrc or ~/.zshrc if the installer suggests it.

  2. On Ubuntu/Debian, install build dependencies:

    sudo apt install pkg-config libssl-dev
  3. Clone the repo and install:

    git clone git@github.com:firebolt-db/fb-cli.git
    cd fb-cli
    cargo install --path . --locked
  4. Run fb (or ~/.cargo/bin/fb if your shell has not picked up Cargo’s bin directory yet).

Shortcuts

Most of them from https://github.com/kkawakam/rustyline:

KeystrokeAction
EnterFinish the line entry
Ctrl-RReverse Search history (Ctrl-S forward, Ctrl-G cancel)
Ctrl-UDelete from start of line to cursor
Ctrl-WDelete word leading up to cursor (using white space as a word boundary)
Ctrl-YPaste from Yank buffer
Ctrl-_Undo

Some of them specific to fb:

KeystrokeAction
Ctrl-CCancel current input.
Ctrl-OInsert a newline

Defaults

Can update defaults one and for all by specifying --update-defaults: during this application old defaults are not applied.

New defaults are going to be stored at ~/.firebolt/fb_config.

~ ➤ fb select 42
?column?
---------
42
Time: 40.342ms
~ ➤ fb select 42 --format CSVWithNames --concise --update-defaults
"?column?"
42
~ ➤ fb select 42
"?column?"
42
~ ➤ fb select 42 --verbose # defauls are merged with new args
URL: http://localhost:8123/?database=local_dev_db&mask_internal_errors=1
QUERY: select 42
"?column?"
42

Queries against FB 2.0 using Service Account

Specify:

  • Service Account ID;
  • Service Account Secret;
  • Environment

Note: The token is saved in ~/.firebolt/fb_sa_token/ and will be reused if the account ID and secret match and the token is less than half an hour old.

➤ fb --sa-id=${SA_ID} --sa-secret=${SA_SECRET} --oauth-env=app \
-h ${ACCOUNT_ID}.api.us-east-1.app.firebolt.io -d ${DATABASE_NAME}

Read more about getting service accounts here.

Queries against FB 2.0

Specify:

  • host;
  • account_id;
  • JWT token (can be obtained from browser or other authentication methods);
➤ fb --host api.us-east-1.app.firebolt.io --verbose --extra account_id=12312312312 --jwt 'eyJhbGciOiJSUzI1NiI...'
=> show engines
URL: https://api.us-east-1.app.firebolt.io/?database=db_1&account_id=12312312&output_format=JSON&advanced_mode=1
QUERY: show engines
┌─engine_name─────────────┬─engine_owner────────────────┬─type─┬─nodes─┬─clusters─┬─status───────────────┬─auto_start─┬─auto_stop─┬─initially_stopped─┬─url────────────────────────────────────────────────────────────────────────────────────────────────────┬─default_database───────────────────┬─version─┬─last_started──────────────────┬─last_stopped──────────────────┬─description─┐
│ pre_demo_engine1 │ user@firebolt.io │ S │ 2 │ 1 │ ENGINE_STATE_STOPPED │ t │ 20 │ f │ api.us-east-1.app.firebolt.io?account_id=1321231&engine=pre_demo_engine1 │ │ latest │ 2024-02-07 01:19:19.81689+00 │ 2024-02-07 01:44:15.930845+00 │ │
│ pre_demo_engine2 │ user@firebolt.io │ S │ 2 │ 1 │ ENGINE_STATE_STOPPED │ t │ 20 │ f │ api.us-east-1.app.firebolt.io?account_id=1321231&engine=pre_demo_engine2 │ pre_demo_validation_testdb1 │ latest │ 2024-02-07 01:21:36.274962+00 │ 2024-02-07 02:32:05.403539+00 │ │
└─────────────────────────┴─────────────────────────────┴──────┴───────┴──────────┴──────────────────────┴────────────┴───────────┴───────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────────────────────────────────┴─────────┴───────────────────────────────┴───────────────────────────────┴─────────────┘
=> set engine=user5_engine_1
URL: https://api.us-east-1.app.firebolt.io/?database=db_1&engine=user5_engine_1&account_id=1321231&output_format=JSON&advanced_mode=1
=> select 42
URL: https://api.us-east-1.app.firebolt.io/?database=db_1&engine=user5_engine_1&account_id=1321231&output_format=JSON&advanced_mode=1
QUERY: select 42
?column?
---------
42
Time: 275.639ms

Set and Unset

In interactive mode one can dynamically update extra arguments:

  • set key=value; to set the argument;
  • unset key; to unset it.
=> select E'qqq';
URL: http://localhost:8123/?database=local_dev_db
QUERY: select E'qqq';
?column?
---------
qqq
Time: 40.745ms
=> set format = Vertical;
=> select E'qqq';
URL: http://localhost:8123/?database=local_dev_db
QUERY: select E'qqq';
Row 1:
──────
?column?: qqq
Time: 38.888ms
=> set cool_mode=disabled;
=> select E'qqq';
URL: http://localhost:8123/?database=local_dev_db&cool_mode=disabled
QUERY: select E'qqq';
Unknown setting cool_mode
Time: 36.802ms
=> unset cool_mode
=> select E'qqq';
URL: http://localhost:8123/?database=local_dev_db
QUERY: select E'qqq';
Row 1:
──────
?column?: qqq
Time: 39.395ms
=> set enable_result_cache=disabled;
=> select E'qqq';
URL: http://localhost:8123/?database=local_dev_db&enable_result_cache=disabled
QUERY: select E'qqq';
Row 1:
──────
qqq: qqq
Time: 41.671ms
=> unset enable_result_cache;
=> select E'qqq';
URL: http://localhost:8123/?database=local_dev_db
QUERY: select E'qqq';
Row 1:
──────
?column?: qqq
Time: 39.453ms
=> 

License

See LICENSE.

About

Firebolt CLI & REPL

Topics

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages