Documentation
¶
Overview ¶
Package datastore holds cloud's one connection to the analytics warehouse — the shared columnar store behind the usage, observability and billing ledgers. Every read and write of a warehouse table in this binary goes through here.
One store, not one per tenant. Rows carry the tenant as a column and as the leading sort key, so a single-org read is a bound predicate over a shared table (WHERE organization = ?) and a fleet-wide aggregate is the same table with that predicate left off. That is the opposite of the relational plane in orgdb.go, where a tenant IS a SQLite file and a cross-tenant read is structurally impossible. The two planes share no connection and are configured independently; keeping them apart is what lets the leaderboard and the admin fleet views span every org while an entity read cannot leave one.
The connection opens from the environment on first use — DATASTORE_ADDR and friends, read by datastore.Env. Open never blocks and never fails, so a warehouse that is down at boot leaves the ledgers unavailable rather than taking down the process that owns them; callers gate on Ready and report an honest gap instead of fabricating zeroes. Because the connection is established once and never replaced, there is no wiring order to get wrong and no window in which a caller sees a half-built client.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Close ¶
func Close() error
Close releases the connection. It is idempotent, and Exec and Query return datastore.ErrUnavailable afterwards.
func EnsureCloudUsage ¶
EnsureCloudUsage creates hanzo.cloud_usage if absent, then applies the additive column migrations so a pre-existing table gains the newer columns. Only SUCCESS latches, so a warehouse still connecting at boot is retried on the next call rather than poisoned forever.
func Exec ¶
Exec runs a statement — engine DDL, or an insert. Placeholders bind positionally from args.
func Query ¶
Query runs a read and materialises the result, decoding each column into its native scan type keyed by column name. Placeholders bind positionally from args and are never interpolated into the statement, so a tenant predicate holds whatever the tenant value contains.
Types ¶
This section is empty.