Command line tool
fsq is a command line client for Firestore built on this crate. It is for working with a database from a terminal: looking at data, trying a SQL statement before it goes into code, and managing indexes.
- a SQL REPL (an interactive prompt) with highlighting, completion of collections and fields, and results as tables, with
\xfor one block per document and\x fullfor the path, type and whole value of every field; EXPLAIN, which draws the query plan as a tree and warns about a table scan, a read of every document of a collection;\llists collections, with\l --recursivefor subcollections, and\ddescribes the fields of a collection;exportandimportof documents as JSON lines, in the tagged encoding of JSON conversion;index plan,index syncand the otherindexcommands, on thefirestore.indexes.jsonfile of the Firebase CLI;codegenand\gen, which print the fluent API code of aSELECT, as Fluent code for a statement describes;--format jsonand--format jsonloutput for scripts.
SQL needs a database of the Enterprise edition, see Standard and Enterprise editions. \l, \d,
export, import and the index commands work on both editions.
Installation
fsq has binaries for Linux, macOS, Windows and FreeBSD on its GitHub releases. The install script picks the one for your system.
On macOS, Linux and FreeBSD:
curl -fsSL https://raw.githubusercontent.com/abdolence/firestore-cli-rs/master/install.sh | sh
On Windows (PowerShell):
irm https://raw.githubusercontent.com/abdolence/firestore-cli-rs/master/install.ps1 | iex
The scripts install the latest release, check its SHA-256 digest and put fsq in ~/.local/bin on macOS, Linux and
FreeBSD, and in %LOCALAPPDATA%\Programs\fsq on Windows. Running a script again upgrades fsq. FSQ_VERSION and
FSQ_INSTALL_DIR choose another release and directory.
With Rust installed, Cargo builds it from source:
cargo install firestore-cli --locked
The crate is firestore-cli and the binary it installs is fsq.
Examples
Connect to a project and a database:
fsq -p my-project -d my-database
Run a statement and print the code of the fluent API for it:
my-project/my-database (enterprise)> SELECT title, rating FROM books WHERE rating >= 4 ORDER BY rating DESC LIMIT 10;
my-project/my-database (enterprise)> \gen
Export a collection and import it again:
fsq -p my-project -d my-database export books -o books.jsonl
fsq -p my-project -d my-database import books.jsonl
Show what changes a firestore.indexes.json file would make, without applying it:
fsq -p my-project index plan firestore.indexes.json
The options and the rest of the commands are in the fsq README.