Expand description
Firebase Realtime Database adapter for the Quarb query engine.
An RTDB is a JSON tree, so the mapping is quarb-json‘s —
objects’ fields (and arrays’ elements) as named children,
scalars carrying the value, traits and ;;;type naming the
JSON kind — but the tree lives on the other end of a REST API
and can be enormous (the public Hacker News database has tens
of millions of nodes), so nothing is ever fetched whole.
Loading model: everything lazy, one node at a time. A node
materializes on first touch with a ?shallow=true GET — a
scalar arrives as its value, a container as its key set — and
is cached for the adapter’s lifetime. Two consequences to
respect: each newly-touched node is one HTTP request, and
unanchored descent (//name) over a large database walks
everything it touches — keep queries anchored the way you’d
keep BigQuery queries off SELECT *.
Properties are direct fetches. ::field on a node GETs
path/field.json — the cheapest possible request (one
scalar, no shallow walk of siblings). This is a deliberate
ergonomic divergence from quarb-json (where fields are only
child hops): on a remote tree, /items/42::score should cost
one tiny request, and does.
References resolve by hint. RTDB has no schema, so ~>
always takes a hint naming a root-relative container:
::parent~>item reads the parent field and lands on
<base>/item/<value> — the same convention as the relational
adapters’ hint (the target “table”). Chains work.
Target syntax: firebase://HOST/BASE/PATH[?QUERY] — e.g.
firebase://hacker-news.firebaseio.com/v0. HTTPS is assumed.
Anything in the query string is appended to every request:
?auth=SECRET (legacy tokens) or ?access_token=TOKEN
(OAuth2) authenticate private databases; public ones need
nothing.
Declared references. The database holds no schema, so the
reference schema can be supplied client-side: a refs
document mapping field names to root-relative target
containers —
{"refs": {"parent": "item", "by": "user", "kids/*": "item"}}
(the field/* form declares an array field whose elements
reference the target). With refs supplied, bare ~> resolves
(::parent~>), and -> crosslinks enumerate: every declared
field with a value becomes a labeled, probed edge, including
one edge per element for array fields. An inline hint always
overrides. Reverse resolution (<~) stays empty: it would
require scanning the referrer container, which is exactly what
opaque containers refuse (a server-side .indexOn query is
the recorded v2 path).
The adapter only ever GETs; the language stays read-only.
Structs§
- Firebase
Adapter - A Firebase Realtime Database (subtree), exposed as an arbor.
Enums§
- Firebase
Error - An error connecting to or reading a database.
Functions§
- parse_
refs - Parse a refs document:
{"refs": {"parent": "item", ...}}.
Type Aliases§
- Refs
- A declared reference schema: field name (or
field/*for array elements) → root-relative target container.