Glesity.Wasm.Data.Abstractions 0.3.0-alpha

This is a prerelease version of Glesity.Wasm.Data.Abstractions.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Glesity.Wasm.Data.Abstractions --version 0.3.0-alpha
                    
NuGet\Install-Package Glesity.Wasm.Data.Abstractions -Version 0.3.0-alpha
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Glesity.Wasm.Data.Abstractions" Version="0.3.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Glesity.Wasm.Data.Abstractions" Version="0.3.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="Glesity.Wasm.Data.Abstractions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Glesity.Wasm.Data.Abstractions --version 0.3.0-alpha
                    
#r "nuget: Glesity.Wasm.Data.Abstractions, 0.3.0-alpha"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Glesity.Wasm.Data.Abstractions@0.3.0-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Glesity.Wasm.Data.Abstractions&version=0.3.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Glesity.Wasm.Data.Abstractions&version=0.3.0-alpha&prerelease
                    
Install as a Cake Tool

Glesity.Wasm.Data.Abstractions

NuGet License: MIT

Zero-reflection, NativeAOT-compatible (wasi-wasm) data attributes, repository contracts, schema migration interfaces, value converters, and exception hierarchy for the Glesity.Wasm data ecosystem:

  • Glesity.Wasm.Sqlite - Embedded SQLite driver with static libsqlite3.a linking and Roslyn Source Generator.
  • Glesity.Wasm.Postgresql (Planned) - Async PostgreSQL driver over WASI sockets.
  • Glesity.Wasm.Redis (Planned) - Async Redis RESP client and key-value store over WASI sockets.

Features

  • 100% NativeAOT & Trimming Safe: Built with zero runtime reflection (IsAotCompatible=true, EnableTrimAnalyzer=true, EnableAotAnalyzer=true).
  • Source Generator Ready: Multi-targeted for netstandard2.0 (for Roslyn Incremental Source Generators) and net11.0 (for WASI / .NET runtimes) with full XML documentation.
  • Rich Schema & Mapping Attributes: Supports [DataEntity], [PrimaryKey], [Column], [Index], [OrderBy], [Flatten], [JsonColumn], [ValueConverter], [DefaultValueConverter], and [Ignore], all validated at construction and marked Inherited = false.
  • Driver-Agnostic Repositories & Migrations: Provides synchronous and asynchronous SQL/KV contracts with pagination (Page/PageAsync), streaming (StreamAllAsync), batch operations (GetMany/SetMany/DeleteMany), and imperative schema migrations (IMigrationStep).

Installation

dotnet add package Glesity.Wasm.Data.Abstractions --prerelease

Quick Start

1. Define Entities, Value Converters & Flattened Structs

Annotate your record, class, or struct models with attributes from Glesity.Wasm.Data.Abstractions:

using System.Text.Json.Serialization;
using Glesity.Wasm.Data.Abstractions;

[DefaultValueConverter]
public readonly struct PlayerIdConverter : IValueConverter<PlayerRef, Guid>
{
    public Guid ToProvider(PlayerRef value) => value.Id;
    public PlayerRef FromProvider(Guid value) => new(value);
}

public readonly record struct PlayerRef(Guid Id);
public readonly record struct BlockPos(int X, int Y, int Z);

[JsonSerializable(typeof(List<string>))]
public partial class AccountJsonContext : JsonSerializerContext;

[DataEntity("player_accounts", Schema = "public")]
public sealed record PlayerAccount(
    [property: PrimaryKey] PlayerRef PlayerId,
    [property: Column("player_name", MaxLength = 32), Index(IsUnique = true)] string Username,
    [property: Flatten] BlockPos SpawnPos,
    [property: JsonColumn(typeof(AccountJsonContext))] List<string> Roles,
    [property: OrderBy(Descending = true)] double Balance,
    bool IsBanned,
    DateTimeOffset LastLogin,
    [property: Ignore] string? TransientSessionToken = null
);

2. Write Driver-Agnostic Application Logic

Program against ISqlRepository<TEntity, TKey>, IAsyncSqlRepository<TEntity, TKey>, IKeyValueStore<TKey, TValue>, or IAsyncKeyValueStore<TKey, TValue>:

using Glesity.Wasm.Data.Abstractions;

public sealed class EconomyService(IAsyncSqlRepository<PlayerAccount, PlayerRef> accounts)
{
    public async ValueTask CreditAsync(PlayerRef playerId, double amount, CancellationToken ct = default)
    {
        var account = await accounts.FindAsync(playerId, ct)
            ?? throw new InvalidOperationException("Player not found.");

        await accounts.UpsertAsync(account with { Balance = account.Balance + amount }, ct);
    }

    public async ValueTask<List<PlayerAccount>> GetPageAsync(int offset, int limit, CancellationToken ct = default)
    {
        return await accounts.PageAsync(offset, limit, ct);
    }
}

Provided Abstractions

Attributes

All attributes enforce runtime argument validation (non-empty strings, positive MaxLength, valid base/interface types) and specify Inherited = false.

Attribute Target Description
[DataEntity(tableName, Schema = ...)] class, struct, record Maps a model to a SQL table or key prefix.
[PrimaryKey(AutoIncrement = ...)] property, parameter Marks the primary key column (AUTOINCREMENT / SERIAL).
[Column(name, IsUnique = ..., MaxLength = ...)] property, parameter Customizes the column name and constraints (UNIQUE, MaxLength > 0).
[Index(name, IsUnique = ...)] property, parameter Declares an index (AllowMultiple = true) for FindBy*, ListBy*, and DeleteBy* generation.
[OrderBy(Descending = true)] property, parameter Generates TopBy<Property>(int limit) leaderboard queries.
[Flatten(Prefix = ...)] property, parameter Expands struct or struct? fields/properties into individual columns.
[JsonColumn(typeof(TContext))] property, parameter Serializes complex objects using an AOT JsonSerializerContext.
[ValueConverter(typeof(TConverter))] assembly, class, struct, property, parameter Maps domain types via IValueConverter<TModel, TProvider>.
[DefaultValueConverter] struct, class Marks an IValueConverter<,> for automatic discovery across referenced assemblies.
[Ignore] property, parameter Excludes a property from persistence mapping.

Repository, Migration & Transaction Contracts

  • ISqlRepository<TEntity, TKey> / IAsyncSqlRepository<TEntity, TKey> - Relational CRUD (EnsureCreated, Insert, InsertIgnore, Upsert, InsertRange, Find, Exists, Delete, DeleteRange, All, Page, StreamAllAsync, Count).
  • IKeyValueStore<TKey, TValue> / IAsyncKeyValueStore<TKey, TValue> - Key-value storage with optional TimeSpan? ttl and batch operations (Get, Set, Delete, Exists, GetMany, SetMany, DeleteMany).
  • IMigrationStep - Imperative schema migration contract (FromVersion, ToVersion, ExecuteSql, AddColumnIfMissing, CreateIndexIfMissing).
  • IDataTransaction / IAsyncDataTransaction - Atomic transaction scopes with IsCompleted tracking, automatic rollback on Dispose / DisposeAsync if uncommitted, and WasmDataTransactionException protection against double completion.

Exceptions

All exceptions carry a numeric ErrorCode, optional InnerException, and a raw ProviderErrorCode (e.g., "SQLITE_CONSTRAINT_UNIQUE" or PostgreSQL SQLSTATE "23505"):

  • WasmDataException - Base exception for all data access errors.
  • WasmDataConnectionException - File open, WASI directory access, or network connection failures.
  • WasmDataConstraintException - UNIQUE, PRIMARY KEY, NOT NULL, FOREIGN KEY, or CHECK constraint violations.
  • WasmDataConflictException (inherits from WasmDataConstraintException) - Uniqueness conflicts or optimistic concurrency serialization failures.
  • WasmDataTimeoutException - Lock wait (SQLITE_BUSY) or command execution timeouts.
  • WasmDataTransactionException - Invalid transaction state transitions (e.g., committing or rolling back an already completed transaction).

Building & Testing

dotnet test -c Release
dotnet pack src/Glesity.Wasm.Data.Abstractions/Glesity.Wasm.Data.Abstractions.csproj -c Release

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Glesity.Wasm.Data.Abstractions:

Package Downloads
Glesity.Wasm.Sqlite

Zero-reflection, NativeAOT-LLVM static SQLite engine for .NET WASI / WebAssembly.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0-alpha.2 83 11/30/2026
0.3.0-alpha.1 67 11/30/2026
0.3.0-alpha 60 11/30/2026
0.2.0-alpha 76 11/29/2026
0.1.0-alpha 84 11/29/2026