Expand description
§Firebase Realtime Database module
This module ports core pieces of the Realtime Database from the Firebase JS SDK to Rust.
It wires the Database component into the FirebaseApp, provides an in-memory backend for quick tests, and can fall back to the REST API for basic reads and writes against an emulator or hosted backend.
Live streaming connections and the richer reference/query surface from the JS SDK are still pending.
It includes error handling, configuration options, and integration with Firebase apps.
§Features
- Component registration and shared get_database resolution
- Reference CRUD with auto-ID push and path navigation (parent/root)
- Priority-aware writes plus server value helpers (server_timestamp increment)
- Snapshot traversal (child, has_child, size, to_json) and value/child listeners
- Dual backends (in-memory + REST) with unit test coverage
§References to the Firebase JS SDK - firestore module
- QuickStart: https://firebase.google.com/docs/database/web/start
- API: https://firebase.google.com/docs/reference/js/database.md#firestore_package
- Github Repo - Module: https://github.com/firebase/firebase-js-sdk/tree/main/packages/database
- Github Repo - API: https://github.com/firebase/firebase-js-sdk/tree/main/packages/firebase/database
§Development status as of 14th October 2025
- Core functionalities: Mostly implemented (see the module’s README.md for details)
- Testing: 30 tests (passed)
- Documentation: Most public functions are documented
- Examples: 2 examples
DISCLAIMER: This is not an official Firebase product, nor it is guaranteed that it has no bugs or that it will work as intended.
§Quick Start Example
use firebase_rs_sdk::app::*;
use firebase_rs_sdk::database::{*, query as compose_query};
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Point to the Realtime Database emulator or a database URL.
let options = FirebaseOptions {
project_id: Some("demo-project".into()),
database_url: Some("http://127.0.0.1:9000/?ns=demo".into()),
..Default::default()
};
let app = initialize_app(options, Some(FirebaseAppSettings::default()))?;
let database = get_database(Some(app))?;
let messages = database.reference("/messages")?;
messages.set(json!({ "greeting": "hello" }))?;
let value = messages.get()?;
assert_eq!(value, json!({ "greeting": "hello" }));
let recent = compose_query(
messages,
vec![order_by_child("timestamp"), limit_to_last(10)],
)?;
let latest = recent.get()?;
println!("latest snapshot: {latest}");
Ok(())
}Modules§
Structs§
- Data
Snapshot - Represents a data snapshot returned to listeners, analogous to the JS
DataSnapshottype. - Database
- Database
Query - Represents a composable database query, analogous to the JS
QueryImpl(packages/database/src/api/Reference_impl.ts). - Database
Reference - Listener
Registration - RAII-style listener registration; dropping the handle detaches the underlying listener.
- OnDisconnect
- Placeholder implementation of the Realtime Database
OnDisconnectAPI. - Query
Constraint - Represents a single constraint produced by helpers such as
order_by_child()(packages/database/src/api/Reference_impl.ts).
Functions§
- end_at
- Mirrors the JS
endAt()constraint (Reference_impl.ts). - end_
at_ with_ key - Mirrors the JS
endAt(value, name)overload (Reference_impl.ts). - end_
before - Mirrors the JS
endBefore()constraint (Reference_impl.ts). - end_
before_ with_ key - Mirrors the JS
endBefore(value, name)overload (Reference_impl.ts). - equal_
to - Mirrors the JS
equalTo()constraint (Reference_impl.ts). - equal_
to_ with_ key - Mirrors the JS
equalTo(value, name)overload (Reference_impl.ts). - get_
database - increment
- Port of
increment()frompackages/database/src/api/ServerValue.ts. - limit_
to_ first - Mirrors the JS
limitToFirst()constraint (Reference_impl.ts). - limit_
to_ last - Mirrors the JS
limitToLast()constraint (Reference_impl.ts). - on_
child_ added - Registers a
child_addedlistener for the provided reference. - on_
child_ changed - Registers a
child_changedlistener for the provided reference. - on_
child_ removed - Registers a
child_removedlistener for the provided reference. - order_
by_ child - Produces a constraint that orders the results by the specified child path.
Mirrors
orderByChild()from the JS SDK. - order_
by_ key - Produces a constraint that orders nodes by key (
orderByKey()in JS). - order_
by_ priority - Produces a constraint that orders nodes by priority (
orderByPriority()in JS). - order_
by_ value - Produces a constraint that orders nodes by value (
orderByValue()in JS). - push
- Generates a child location with an auto-generated push ID.
- push_
with_ value - Generates a child location with an auto-generated push ID and writes the provided value.
- query
- Creates a derived query by applying the provided constraints, following the
semantics of
query()inpackages/database/src/api/Reference_impl.ts. - register_
database_ component - run_
transaction - Runs a transaction at the provided reference (currently unimplemented).
- server_
timestamp - Port of
serverTimestamp()frompackages/database/src/api/ServerValue.ts. - set_
priority - Updates the priority for the current location, mirroring the modular
setPriority()helper (packages/database/src/api/Reference_impl.ts). - set_
with_ priority - Writes a value together with a priority, mirroring the modular
setWithPriority()helper (packages/database/src/api/Reference_impl.ts). - start_
after - Mirrors the JS
startAfter()constraint (Reference_impl.ts). - start_
after_ with_ key - Mirrors the JS
startAfter(value, name)overload (Reference_impl.ts). - start_
at - Mirrors the JS
startAt()constraint (Reference_impl.ts). - start_
at_ with_ key - Mirrors the JS
startAt(value, name)overload (Reference_impl.ts).