<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://johnwick.cc/index.php?action=history&amp;feed=atom&amp;title=Building_a_Firestore_Database_CLI_with_Rust</id>
	<title>Building a Firestore Database CLI with Rust - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://johnwick.cc/index.php?action=history&amp;feed=atom&amp;title=Building_a_Firestore_Database_CLI_with_Rust"/>
	<link rel="alternate" type="text/html" href="https://johnwick.cc/index.php?title=Building_a_Firestore_Database_CLI_with_Rust&amp;action=history"/>
	<updated>2026-05-07T00:00:06Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.1</generator>
	<entry>
		<id>https://johnwick.cc/index.php?title=Building_a_Firestore_Database_CLI_with_Rust&amp;diff=119&amp;oldid=prev</id>
		<title>PC: Created page with &quot;This article leverages the Gemini CLI and the underlying Gemini LLM to develop native compiled code built in the Rust Language for integration to the Firestore NOSQL database. A fully functional CLI is developed in Rust for interacting with a remote Firestore database hosted in Google Cloud directly from the command line. What is Rust? Rust is a high performance, memory safe, compiled language: Rust A language empowering everyone to build reliable and efficient software....&quot;</title>
		<link rel="alternate" type="text/html" href="https://johnwick.cc/index.php?title=Building_a_Firestore_Database_CLI_with_Rust&amp;diff=119&amp;oldid=prev"/>
		<updated>2025-11-15T17:05:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This article leverages the Gemini CLI and the underlying Gemini LLM to develop native compiled code built in the Rust Language for integration to the Firestore NOSQL database. A fully functional CLI is developed in Rust for interacting with a remote Firestore database hosted in Google Cloud directly from the command line. What is Rust? Rust is a high performance, memory safe, compiled language: Rust A language empowering everyone to build reliable and efficient software....&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This article leverages the Gemini CLI and the underlying Gemini LLM to develop native compiled code built in the Rust Language for integration to the Firestore NOSQL database. A fully functional CLI is developed in Rust for interacting with a remote Firestore database hosted in Google Cloud directly from the command line.&lt;br /&gt;
What is Rust?&lt;br /&gt;
Rust is a high performance, memory safe, compiled language:&lt;br /&gt;
Rust&lt;br /&gt;
A language empowering everyone to build reliable and efficient software.&lt;br /&gt;
www.rust-lang.org&lt;br /&gt;
&lt;br /&gt;
Rust provides memory safe operations beyond C/C++ and also can provide exceptional performance gains as it is compiled directly to native binaries.&lt;br /&gt;
Initial Environment Setup&lt;br /&gt;
The environment is meant to be run from a Bash like shell. You can run this from a Linux VM, ChromeOS Linux VM, Firebase Studio environment, or any environment that provides a basic shell.&lt;br /&gt;
Rust Setup&lt;br /&gt;
Instructions to install Rust are available here:&lt;br /&gt;
Getting started&lt;br /&gt;
A language empowering everyone to build reliable and efficient software.&lt;br /&gt;
www.rust-lang.org&lt;br /&gt;
&lt;br /&gt;
For a Linux like environment the command looks like this:&lt;br /&gt;
curl — proto ‘=https’ — tlsv1.2 -sSf https://sh.rustup.rs | sh&lt;br /&gt;
What is Firestore?&lt;br /&gt;
Google Firestore, also known as Cloud Firestore is a part of the Google Firebase application development platform. It is fundamentally a cloud-hosted NoSQL database for storing and syncing data. Firestore can be directly accessed by mobile and web applications through native SDKs.&lt;br /&gt;
Cloud Firestore | Store and sync app data at global scale&lt;br /&gt;
Discover Firebase, Google’s mobile and web app development platform that helps developers build apps and games that…&lt;br /&gt;
firebase.google.com&lt;br /&gt;
&lt;br /&gt;
Rust Deployment Strategy&lt;br /&gt;
Rust has not been the typical deployment path for Firestore software development — so a step by step approach is used with validation at each milestone.&lt;br /&gt;
Clone the Samples Repo and Setup the Basic Environment&lt;br /&gt;
Now that the Gemini CLI and the Rust installation has been validated from the base shell — you can clone the GitHub Repo with support scripts:&lt;br /&gt;
cd ~&lt;br /&gt;
git clone https://github.com/xbill9/gemini-cli-codeassist&lt;br /&gt;
Then run init.sh from the cloned directory. The script will attempt to determine your shell environment and set the correct variables:&lt;br /&gt;
cd gemini-cli-codeassist&lt;br /&gt;
source init.sh&lt;br /&gt;
Set application default credentials for authentication:&lt;br /&gt;
gcloud auth application-default login&lt;br /&gt;
Debugging API Permission Errors&lt;br /&gt;
If your application default credentials expires or your Google Cloud Authentication expires you will get an error similar to this:&lt;br /&gt;
Finished `dev` profile [unoptimized + debuginfo] target(s) in 27.94s&lt;br /&gt;
     Running `target/debug/firestore-client-rust`&lt;br /&gt;
Starting client API call Project comglitn&lt;br /&gt;
Error: Error { kind: Authentication, source: Some(CredentialsError { is_transient: false, message: Some(&amp;quot;Request to fetch the token failed. Subsequent calls with this credential will also fail.&amp;quot;), source: Some(Error { kind: Authentication, source: Some(CredentialsError { is_transient: false, message: Some(&amp;quot;failed to refresh user access token, body=&amp;lt;{\n  \&amp;quot;error\&amp;quot;: \&amp;quot;invalid_grant\&amp;quot;,\n  \&amp;quot;error_description\&amp;quot;: \&amp;quot;reauth related error (invalid_rapt)\&amp;quot;,\n  \&amp;quot;error_uri\&amp;quot;: \&amp;quot;https://support.google.com/a/answer/9368756\&amp;quot;,\n  \&amp;quot;error_subtype\&amp;quot;: \&amp;quot;invalid_rapt\&amp;quot;\n}&amp;gt;&amp;quot;), source: Some(reqwest::Error { kind: Status(400, None), url: &amp;quot;https://oauth2.googleapis.com/token&amp;quot; }) }) }) }) }&lt;br /&gt;
The workaround is to re-authenticate:&lt;br /&gt;
gcloud auth login&lt;br /&gt;
gcloud auth application-default login&lt;br /&gt;
Another common error is that the environment variables are not set correctly. Go the the root directory and re-run the set_env.sh to set the variables:&lt;br /&gt;
cd ~/gemini-cli-codeassist&lt;br /&gt;
source set_env.sh&lt;br /&gt;
Basic Firestore Library in Rust Native Code&lt;br /&gt;
The first step is to build a minimal Rust client sample that connects to Firestore using the Rust native Firestore libraries. The most popular implementation is the firestore crate:&lt;br /&gt;
firestore — Rust&lt;br /&gt;
Firestore for Rust&lt;br /&gt;
docs.rs&lt;br /&gt;
GitHub — abdolence/firestore-rs: Google Firestore for Rust based on gRPC API with Serde serializer&lt;br /&gt;
Google Firestore for Rust based on gRPC API with Serde serializer — abdolence/firestore-rs&lt;br /&gt;
github.com&lt;br /&gt;
&lt;br /&gt;
Debugging and Logging with Rust&lt;br /&gt;
The environment variable RUST_LOG controls how verbose the logging from the Rust code will produce messages. Initially — set the variable to info:&lt;br /&gt;
export RUST_LOG=info&lt;br /&gt;
echo $RUST_LOG&lt;br /&gt;
info&lt;br /&gt;
Rust Log Levels&lt;br /&gt;
These levels filter messages based on their severity, from most critical to least:&lt;br /&gt;
* 		ERROR: Only error messages are logged.&lt;br /&gt;
* 		WARN: Warning messages and higher (error) are logged.&lt;br /&gt;
* 		INFO: Informational messages and higher (warn, error) are logged.&lt;br /&gt;
* 		DEBUG: Debug messages and higher (info, warn, error) are logged.&lt;br /&gt;
* 		TRACE: Trace messages and higher (debug, info, warn, error) are logged. This is the most verbose level.&lt;br /&gt;
* 		OFF: Disables all logging.&lt;br /&gt;
Next Steps- Build Rust Sample Client Code&lt;br /&gt;
A basic native Rust client sample the makes a direct connection to Firestore has been included in the GitHub repo. Change to the sample directory and validate the Cargo.toml file for the minimal sample:&lt;br /&gt;
cd ~/gemini-cli-codeassist/firestore-cli-rust&lt;br /&gt;
pwd&lt;br /&gt;
/home/xbill/gemini-cli-codeassist/firestore-cli-rust&lt;br /&gt;
The Rust standard format file Cargo.toml contains details about the code:&lt;br /&gt;
head Cargo.toml&lt;br /&gt;
[package]&lt;br /&gt;
name = &amp;quot;firestore-cli-rust&amp;quot;&lt;br /&gt;
version = &amp;quot;0.1.0&amp;quot;&lt;br /&gt;
edition = &amp;quot;2024&amp;quot;&lt;br /&gt;
description = &amp;quot;Basic Rust local Connection CLI tool to Firestore&amp;quot;&lt;br /&gt;
license = &amp;quot;MIT&amp;quot;&lt;br /&gt;
repository = &amp;quot;https://github.com/xbill9/gemini-cli-codeassist&amp;quot;&lt;br /&gt;
Build the Firestore client sample with the Makefile:&lt;br /&gt;
xbill@penguin:~/gemini-cli-codeassist/firestore-cli-rust$ make release&lt;br /&gt;
Building Release...&lt;br /&gt;
   Compiling firestore-cli-rust v0.1.0 (/home/xbill/gemini-cli-codeassist/firestore-cli-rust)&lt;br /&gt;
    Finished `release` profile [optimized] target(s) in 7.38s&lt;br /&gt;
Then run the generated Rust binary:&lt;br /&gt;
./target/release/firestore-cli-rust &lt;br /&gt;
Basic Rust local Connection CLI tool to Firestore&lt;br /&gt;
firestore-cli&amp;gt; help&lt;br /&gt;
Basic Rust local CLI tool to Firestore&lt;br /&gt;
Usage: firestore-cli-rust &amp;lt;COMMAND&amp;gt;&lt;br /&gt;
Commands:&lt;br /&gt;
  seed    Seeds the Firestore database with initial product data&lt;br /&gt;
  list    Lists all products in the Firestore database&lt;br /&gt;
  get     Gets a product by its ID from the Firestore database&lt;br /&gt;
  search  Searches for products by name&lt;br /&gt;
  help    Print this message or the help of the given subcommand(s)&lt;br /&gt;
Options:&lt;br /&gt;
  -h, --help     Print help&lt;br /&gt;
  -V, --version  Print version&lt;br /&gt;
firestore-cli&amp;gt; &lt;br /&gt;
The Firestore integration has been bundled as a basic CLI in the firestore-cli-rust binary to allow real-time validation of the connection to Firestore from the Rust client code.&lt;br /&gt;
Seed the Firestore Database with Sample Data&lt;br /&gt;
To pre-populate the sample test data in the Firestore database- use the seed command:&lt;br /&gt;
./target/release/firestore-cli-rust seed&lt;br /&gt;
2025-10-10T15:17:38.497028Z  INFO firestore::db: Creating a new database client. database_path=&amp;quot;projects/comglitn/databases/(default)&amp;quot; api_url=&amp;quot;https://firestore.googleapis.com&amp;quot; token_scopes=&amp;quot;https://www.googleapis.com/auth/cloud-platform&amp;quot;&lt;br /&gt;
2025-10-10T15:17:38.615203Z  INFO firestore_client_rust: Seeding database...&lt;br /&gt;
2025-10-10T15:17:44.374093Z  INFO firestore_client_rust: Database seeded successfully.&lt;br /&gt;
Get a List of Products from Firestore&lt;br /&gt;
This command lists the products that have just been seeded:&lt;br /&gt;
./target/release/firestore-cli-rust list&lt;br /&gt;
2025-10-10T15:19:32.689483Z  INFO firestore_client_rust: Product { id: None, name: &amp;quot;Sunflower Seeds&amp;quot;, price: 2.0, quantity: 337, imgfile: &amp;quot;product-images/sunflowerseeds.png&amp;quot;, timestamp: 2025-03-02T07:20:37.494Z, actualdateadded: 2025-09-23T15:39:43.851Z }&lt;br /&gt;
2025-10-10T15:19:32.689492Z  INFO firestore_client_rust: Product { id: None, name: &amp;quot;Parmesan Crisps&amp;quot;, price: 4.0, quantity: 69, imgfile: &amp;quot;product-images/parmesancrisps.png&amp;quot;, timestamp: 2025-09-19T22:43:17.206Z, actualdateadded: 2025-09-23T15:39:44.035Z }&lt;br /&gt;
2025-10-10T15:19:32.689502Z  INFO firestore_client_rust: Product { id: None, name: &amp;quot;Black Beans&amp;quot;, price: 7.0, quantity: 488, imgfile: &amp;quot;product-images/blackbeans.png&amp;quot;, timestamp: 2024-09-16T18:02:45.258Z, actualdateadded: 2025-09-23T15:39:42.844Z }&lt;br /&gt;
Lookup A Product by ID&lt;br /&gt;
Another feature of the client is to look up a product by the Firestore ID:&lt;br /&gt;
./target/release/firestore-cli-rust list | grep coffee&lt;br /&gt;
2025-10-10T15:21:42.964343Z  INFO firestore_client_rust: Product { id: Some(&amp;quot;28JSxzPTzljYcwUvUZUH&amp;quot;), name: &amp;quot;Coffee Beans&amp;quot;, price: 8.318669309680374, quantity: 211, imgfile: &amp;quot;product-images/coffeebeans.png&amp;quot;, timestamp: 2024-12-31T15:17:38.615278383Z, actualdateadded: 2025-10-10T15:17:38.615278608Z }&lt;br /&gt;
2025-10-10T15:21:42.964612Z  INFO firestore_client_rust: Product { id: None, name: &amp;quot;Coffee Beans&amp;quot;, price: 2.0468191712577912, quantity: 480, imgfile: &amp;quot;product-images/coffeebeans.png&amp;quot;, timestamp: 2024-10-14T20:40:44.060282548Z, actualdateadded: 2025-10-09T20:40:44.060283278Z }&lt;br /&gt;
xbill@penguin:~/gemini-cli-codeassist/firestore-client-rust$ ./target/release/firestore-client-rust get 28JSxzPTzljYcwUvUZUH&lt;br /&gt;
2025-10-10T15:21:54.307875Z  INFO firestore::db: Creating a new database client. database_path=&amp;quot;projects/comglitn/databases/(default)&amp;quot; api_url=&amp;quot;https://firestore.googleapis.com&amp;quot; token_scopes=&amp;quot;https://www.googleapis.com/auth/cloud-platform&amp;quot;&lt;br /&gt;
2025-10-10T15:21:54.368794Z  INFO firestore_client_rust: Fetching product by id: 28JSxzPTzljYcwUvUZUH&lt;br /&gt;
2025-10-10T15:21:54.733277Z  INFO firestore_client_rust: Found product: Product { id: Some(&amp;quot;28JSxzPTzljYcwUvUZUH&amp;quot;), name: &amp;quot;Coffee Beans&amp;quot;, price: 8.318669309680374, quantity: 211, imgfile: &amp;quot;product-images/coffeebeans.png&amp;quot;, timestamp: 2024-12-31T15:17:38.615278383Z, actualdateadded: 2025-10-10T15:17:38.615278608Z }&lt;br /&gt;
xbill@penguin:~/gemini-cli-codeassist/firestore-client-rust$&lt;br /&gt;
Perform a Code Review with Rust Tools&lt;br /&gt;
First — basic Rust tools are used to review and check the code. The key Rust tool for lint code is clippy:&lt;br /&gt;
GitHub — rust-lang/rust-clippy: A bunch of lints to catch common mistakes and improve your Rust…&lt;br /&gt;
A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/ …&lt;br /&gt;
github.com&lt;br /&gt;
The main commands include —&lt;br /&gt;
Checking versions in Cargo.toml for updates:&lt;br /&gt;
cargo update&lt;br /&gt;
Checking for syntax issues:&lt;br /&gt;
cargo check&lt;br /&gt;
Linting code:&lt;br /&gt;
cargo clippy&lt;br /&gt;
Formatting code:&lt;br /&gt;
cargo fmt&lt;br /&gt;
Deep Dive with Rust Logging&lt;br /&gt;
Update the RUST_LOG environment variable to a more granular level to get deeper visibility into the Firestore connection :&lt;br /&gt;
export RUST_LOG=debug&lt;br /&gt;
echo $RUST_LOG&lt;br /&gt;
debug&lt;br /&gt;
&lt;br /&gt;
Now re-run the Firestore connection with the new log level:&lt;br /&gt;
./target/release/firestore-cli-rust get 28JSxzPTzljYcwUvUZUH&lt;br /&gt;
2025–10–10T15:51:02.711441Z INFO firestore::db: Creating a new database client. database_path=”projects/comglitn/databases/(default)” api_url=”https://firestore.googleapis.com&amp;quot; token_scopes=”https://www.googleapis.com/auth/cloud-platform&amp;quot;&lt;br /&gt;
2025–10–10T15:51:02.711480Z DEBUG gcloud_sdk::api_client: Creating a new Google API client for https://firestore.googleapis.com. Scopes: [“https://www.googleapis.com/auth/cloud-platform&amp;quot;]&lt;br /&gt;
2025–10–10T15:51:02.735501Z DEBUG rustls::webpki::anchors: add_parsable_certificates processed 143 valid and 0 invalid certs&lt;br /&gt;
2025–10–10T15:51:03.330295Z DEBUG Connection{peer=Client}: h2::codec::framed_write: send frame=Ping { ack: true, payload: [0, 0, 0, 0, 0, 0, 2, 28] }&lt;br /&gt;
2025–10–10T15:51:03.331053Z DEBUG gcloud_sdk::middleware: OK: /google.firestore.v1.Firestore/GetDocument took 524ms (incl. token gen: 156ms)&lt;br /&gt;
2025–10–10T15:51:03.331306Z DEBUG Firestore Get Doc{/firestore/collection_name=”inventory” /firestore/document_name=”projects/comglitn/databases/(default)/documents/inventory/28JSxzPTzljYcwUvUZUH” /firestore/response_time=524}: firestore::db::get: Read document. document_path=”projects/comglitn/databases/(default)/documents/inventory/28JSxzPTzljYcwUvUZUH” duration_milliseconds=524&lt;br /&gt;
2025–10–10T15:51:03.331659Z INFO firestore_client_rust: Found product: Product { id: Some(“28JSxzPTzljYcwUvUZUH”), name: “Coffee Beans”, price: 8.318669309680374, quantity: 211, imgfile: “product-images/coffeebeans.png”, timestamp: 2024–12–31T15:17:38.615278383Z, actualdateadded: 2025–10–10T15:17:38.615278608Z }&lt;br /&gt;
Package Information on crates.io&lt;br /&gt;
The complete firestore-cli-rust is available on the Rust crates.io site:&lt;br /&gt;
crates.io: Rust Package Registry&lt;br /&gt;
Edit description&lt;br /&gt;
crates.io&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Summary&lt;br /&gt;
A complete Rust native CLI client was built and testing using the Gemini CLI along with Rust libraries for a direct connection to Google Firestore- a NOSQL database hosted in Google Cloud. This compiled Rust code was then called directly from the local shell and performed interactive operations against the backing Firestore Database.&lt;br /&gt;
The overall goal was to validate the Rust Firestore client libraries and the environment needed to successfully connect to a Firestore Database from Rust native compiled code.&lt;/div&gt;</summary>
		<author><name>PC</name></author>
	</entry>
</feed>