Documentation
¶
Overview ¶
Sharding example (F6-7, ADR-0016).
A ShardRouter partitions data horizontally across N shard databases. Each row lives in exactly one shard, chosen by a shard key supplied per query via context. The router implements quark.ClientProvider, so quark.For[T](ctx, router) routes the query to the owning shard's *Client and runs unchanged — the rest of the ORM is unaware sharding exists.
This example is self-contained: it uses two file-based SQLite databases as shards so it runs with `go run ./examples/sharding/main.go` and no Docker. Sharding is engine-agnostic — to shard across real Postgres/MySQL instances, open each shard with that driver/DSN; the routing code is identical.
Hard limits (ADR-0016): no implicit cross-shard fan-out (a query without a shard key is an error), no cross-shard joins, and no cross-shard transactions (a Tx is bound to one shard's Client). Design the model so each operation stays inside a single shard.