| 1 | // Package storage owns a tenant's SQLite database and the transaction boundary |
| 2 | // for event data, projections and durable work intents. |
| 3 | // |
| 4 | // Open creates the database and schema with SQLite WAL mode, full synchronous |
| 5 | // writes, foreign-key enforcement and one database connection. Each method |
| 6 | // uses its context for database work. |
| 7 | // |
| 8 | // Save applies duplicate, deletion and replacement rules, stores searchable |
| 9 | // indexes and inserts durable work intents in one transaction. Callers validate |
| 10 | // events before passing them to storage. |
| 11 | // SaveTx performs the same operation inside a transaction supplied by the |
| 12 | // caller. The caller owns that transaction and commits it after SaveTx |
| 13 | // succeeds. WithTx provides the matching begin, commit and rollback boundary; |
| 14 | // its callback uses the supplied *sql.Tx for all database operations. |
| 15 | // |
| 16 | // Query excludes expired, hidden and pending events and applies recipient |
| 17 | // checks through QueryOptions.Access. It returns events in created-at |
| 18 | // descending order with ID ascending as the stable tie breaker. The tenant |
| 19 | // gate applies the remaining policy and resource visibility rules. After |
| 20 | // reads events by their increasing insertion sequence for cursored |
| 21 | // replication; removed events leave gaps in that sequence. |
| 22 | package storage |