You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 907b617
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: readme.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,7 @@ A lightweight, multi-provider document store for .NET that turns relational data
56
56
-**Per-query change monitoring** — call `.NotifyOnChange()` on any query to receive only the changes whose document matches the query's `Where` predicates: `await foreach (var c in store.Query<Order>().Where(o => o.Status == "Pending").NotifyOnChange(ct)) { ... }`. Property-level / removal / clear events that don't carry the document body are passed through so the consumer can re-check membership.
57
57
-**Global query filters** — `options.AddQueryFilter<User>(u => !u.IsDeleted)` registers a predicate that's automatically AND-applied to every query of `User` — including `Query<T>()`, single-doc paths (`Get`/`Update`/`Remove`/`SetProperty`/`RemoveProperty`/`Clear`), bulk operations (`ExecuteUpdate`/`ExecuteDelete`), and per-query change monitoring. Named filters can be disabled individually via `query.IgnoreQueryFilters("name")`; all filters can be disabled with `query.IgnoreQueryFilters()`. Use for soft-delete, row-level security, or "active only" scopes. Insert is intentionally unfiltered (matches Entity Framework Core).
58
58
- **Temporal history (system-time versioning)** — `options.MapTemporal<Order>(o => { o.Retention = TimeSpan.FromDays(90); o.MaxVersions = 50; o.CaptureActor = () => userId; })` opts a type into append-only versioning. **Scope-aware actor:** `o.ResolveActor = sp => sp.GetService<ICurrentUser>()?.Id` captures "who" from the write's request-scoped DI (per unit of work), taking precedence over `CaptureActor`. Every Insert/Update/Upsert/Remove/SetProperty/RemoveProperty/BatchInsert (including inside a session) records a snapshot to a per-type history sidecar. Read it back with `History<T>(id)`, `AsOf<T>(id, when)`, `Restore<T>(id, version)`, `GetDiffBetween<T>(id, from, to)`, plus fleet-wide `AsOfAll<T>(when)`, `ChangesByActor<T>(actor)`, and `ChangesBetween<T>(from, to)`. Opt-in per type (non-temporal types pay nothing); supported on **every** provider — all relational (SQLite, SQLCipher, PostgreSQL, SQL Server, MySQL, Oracle, DuckDB) and the document stores (LiteDB, MongoDB, CosmosDB, IndexedDB). The history methods live on the `ITemporalDocumentStore` capability interface (not `IDocumentStore`) — resolve or cast to it. Retention pruned on every write.
59
+
- **Blobs (binary payloads in a sidecar)** — attach binary data (PDFs, images, signatures) to a document without bloating it. Map a `DocumentBlob` (single) or `DocumentBlobCollection` (many) with `MapBlob<T>` / `MapBlobCollection<T>`, and the bytes go to a `{table}_blobs` sidecar table while only the metadata (length, content type, file name) rides along in the document JSON — so ordinary queries never drag the payload along, and you can `Where`/`OrderBy` on that metadata like any other property (`Where(x => x.Pdf.Length > 1_000_000)`). Payloads self-load: `await doc.Pdf.LoadAsync()` for one blob, `await doc.Attachments.LoadAllAsync()` for a whole collection in one round trip (or `store.BatchLoadBlobs(page)` across a page, `store.GetBlob<T>(id, key)` with no document in hand); `Bytes` throws until loaded, so there's no hidden I/O behind a property getter. Writes go through the document (assign the member and save — no `SetBlob`), so the inline metadata can never disagree with the stored bytes; deleting a document cascades to its blob rows. Opt-in SHA-256 hashing and a per-mapping size ceiling; `store.MaxBlobSize` reports the provider limit. Use it instead of a raw `byte[]` property (which is base64'd into the document body and read on every query). **Relational providers only** (SQLite, PostgreSQL/CockroachDB, SQL Server, MySQL/MariaDB, Oracle, DuckDB); NoSQL providers report `MaxBlobSize == 0` and throw.
59
60
-**Native change feeds (`IChangeFeedDocumentStore`)** — observe changes from *any* writer (other processes/connections), not just this instance: `await using var sub = await store.SubscribeChanges<User>(async (change, ct) => { ... });`. Backed by each database's own mechanism — **PostgreSQL**`LISTEN`/`NOTIFY` (row-level triggers, true push), **SQL Server** Change Tracking with optional `SqlDependency` query-notification wake-ups (configurable via `SqlServerChangeFeedOptions`), and **CosmosDB** Change Feed. Provisioning (triggers / enabling change tracking) is automatic and idempotent. Dispose the returned handle to stop. (SQLite, LiteDB, IndexedDB, MySQL and Oracle have no proper external-change mechanism and throw `NotSupportedException`.)
60
61
-**Concurrent operations on server SQL** — a single `DocumentStore` instance backed by PostgreSQL, MySQL, SQL Server, or Oracle opens a fresh connection per operation and lets the ADO.NET driver pool multiplex callers. No per-store semaphore. SQLite and DuckDB (embedded engines that lock the whole DB on writes) keep the long-lived shared connection + serialization model. Providers opt in to shared mode via `IDatabaseProvider.RequiresSingleConnection`. Table init is exactly-once per table across concurrent first-touch callers (`ConcurrentDictionary<string, Lazy<Task>>`).
61
62
- **Unit of work (`IDocumentSession`)** — the document store is a connection: open a short-lived session and group writes into one transaction: `await using var session = store.OpenSession(); session.Add(a).Update(b).Remove<C>(id); await session.SaveChanges();` with automatic commit/rollback. Contiguous same-type runs of inserts, upserts, updates, and removes are each coalesced into the matching batch method. Inject `IDocumentSession` (scoped) in ASP.NET via `AddScopedDocumentSession()`, or open one from the singleton `IDocumentSessionFactory` (MAUI/desktop/background — mirrors EF's `IDbContextFactory`). For finer control the session exposes an explicit transaction — `await using var tx = await session.BeginTransaction();` — for locking reads (`session.Get(id, LockMode.Update)`) and grouping `ExecuteUpdate`/`ExecuteDelete`; `SaveChanges` joins it. Pass an `IsolationLevel` (`BeginTransaction(IsolationLevel.Snapshot)`) for a **consistent-read session**. (Replaces the removed `CreateUnitOfWork()`/`UnitOfWork`.)
Region boundaries are intentionally low-resolution (coarse containment, not cartography). The embedded city lists are regenerated from US Census / Statistics Canada by the dev-only `tools/Shiny.DocumentDb.Geo.DataSeeder` (not part of CI).
1576
1584
1585
+
## Blobs (MapBlob / MapBlobCollection)
1586
+
1587
+
Binary payloads (PDF, image, signature) attached to a document. The bytes go to a `{table}_blobs`**sidecar table**, not the document JSON; only metadata (length, content type, file name) rides along in the body. **Use `DocumentBlob` instead of a raw `byte[]` property** — a `byte[]` is base64'd into the document body and materialized on every read.
1588
+
1589
+
**Supported on every server-side provider** — relational (SQLite, PostgreSQL/CockroachDB, SQL Server, MySQL/MariaDB, Oracle, DuckDB) and document/NoSQL (LiteDB, MongoDB/Amazon DocumentDB, Redis, Azure Table, DynamoDB, Cosmos, Firestore, RavenDB-native-attachments). **Only IndexedDB (Blazor WASM) is unsupported** — it reports `store.MaxBlobSize == 0` and **throws `NotSupportedException`**. Per-provider caps vary (Azure Table 64KB, DynamoDB 390KB, Cosmos 1.4MB, Firestore/LiteDB 1-16MB, relational/Redis/Raven ≥512MB) — check `store.MaxBlobSize`.
1590
+
1591
+
```csharp
1592
+
publicclassInvoice
1593
+
{
1594
+
publicstringId { get; set; } ="";
1595
+
publicDocumentBlob? Pdf { get; set; } // single
1596
+
publicDocumentBlobCollectionAttachments { get; set; } =new(); // many — NOT List<DocumentBlob>
// options: o => { o.Key = "sig"; o.ComputeHash = true; o.MaxSize = 256*1024; } (ComputeHash OFF by default)
1605
+
});
1606
+
```
1607
+
1608
+
**Write** — assign the member and save the document; there is NO `SetBlob`. Metadata can never disagree with the bytes because every mutation goes through the document.
Deleting a document cascades to its blob rows. `store.MaxBlobSize` (bytes) reports the provider ceiling; `0` = unsupported. Backup includes payloads by default (`ExportAsync(stream, new BackupExportOptions { IncludeBlobs = false })` to skip). Blobs are **not** temporally versioned — `Restore` keeps current blobs. `IDocumentMaintenance.SweepOrphanedBlobs<T>()` reclaims rows whose document is gone.
1645
+
1577
1646
## Temporal History (System-Time Versioning)
1578
1647
1579
1648
Opt-in append-only versioning per type. Enable with `MapTemporal<T>` on the options; every `Insert`/`Update`/`Upsert`/`Remove`/`SetProperty`/`RemoveProperty`/`BatchInsert` (including writes inside a `UnitOfWork`) records a versioned snapshot to a per-type history sidecar. Only mapped types incur the extra write.
0 commit comments