Skip to content

Data Store

The Data Store module generates complete persistence abstractions from [DataStore] and [StoredEntity] attributes — store interfaces, in-memory implementations, effect methods, capability interfaces, and DI registration.

Quick Start

Define a store and an entity:

using Deepstaging.DataStore;

[DataStore]
public static partial class AppStore;

[StoredEntity]
public partial record Article(ArticleId Id, string Title, string Body);

This generates:

  • IArticleStore — async CRUD interface with pagination
  • InMemoryArticleStoreConcurrentDictionary-backed test implementation
  • IHasAppStore — capability interface for runtime access
  • AppStore.Articles.*Eff<RT, T> effect methods
  • AddAppStore — DI registration extension method

Compose with effect pipelines:

var program =
    from article in AppStore.Articles.GetById<AppRuntime>(articleId)
    from _ in guard(article.IsSome, Error.New("Article not found"))
              >> AppStore.Articles.Save<AppRuntime>(article.Value! with { Title = "Updated" })
    select unit;

What's Next

Page Description
Attribute Reference [DataStore], [StoredEntity], [ForeignKey<T>], [CompositeKey], [Lookup] — targets, properties, defaults, and constraints
Generated Code Store interfaces, in-memory implementations, result types, DI registration — plain .NET with async/await
Effects Composition Capability interfaces, Eff<RT, T> methods, OpenTelemetry tracing, runtime composition, and Postgres backend

Diagnostics

ID Severity Description Code Fix
DSDS01 Error [DataStore] class must be partial Add partial modifier
DSDS02 Warning [DataStore] class should be static Add static modifier
DSDS03 Error [StoredEntity] must be partial Add partial modifier
DSDS04 Error [StoredEntity] must have a [TypedId] property
DSDS05 Error Only one [DataStore] per assembly
DSDS06 Error [ForeignKey<T>] target must be a [StoredEntity]
DSDS07 Error [CompositeKey] property not found
DSDS08 Error [StoredEntity] requires [DataStore] in assembly