SquidStd.Database 0.35.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SquidStd.Database --version 0.35.0
                    
NuGet\Install-Package SquidStd.Database -Version 0.35.0
                    
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="SquidStd.Database" Version="0.35.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SquidStd.Database" Version="0.35.0" />
                    
Directory.Packages.props
<PackageReference Include="SquidStd.Database" />
                    
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 SquidStd.Database --version 0.35.0
                    
#r "nuget: SquidStd.Database, 0.35.0"
                    
#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 SquidStd.Database@0.35.0
                    
#: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=SquidStd.Database&version=0.35.0
                    
Install as a Cake Addin
#tool nuget:?package=SquidStd.Database&version=0.35.0
                    
Install as a Cake Tool

<h1 align="center">SquidStd.Database</h1>

FreeSql-backed implementation of the SquidStd.Database.Abstractions contracts. It owns a singleton IFreeSql, exposes a generic FreeSqlDataAccess<TEntity> with transactional writes (rollback on failure), bulk operations and paging, parses URI-style connection strings, and can auto-sync the schema on startup.

Install

dotnet add package SquidStd.Database

Usage

using DryIoc;
using SquidStd.Database.Abstractions.Interfaces.Data;
using SquidStd.Database.Extensions;

var container = new Container();
container.RegisterDatabase(); // reads the "database" config section

// DatabaseConfig: ConnectionString = "postgres://user:pass@host:5432/app", AutoMigrate = true
var users = container.Resolve<IDataAccess<User>>();
await users.InsertAsync(new User { Name = "Ann" });
var page = await users.GetPagedAsync(page: 1, pageSize: 20, orderBy: u => u.Name);

Key types

Type Purpose
RegisterDatabaseExtension RegisterDatabase() DI registration.
DatabaseService Owns the singleton IFreeSql; builds it and (optionally) migrates.
FreeSqlDataAccess<TEntity> FreeSql IDataAccess<TEntity> implementation.
ConnectionStringParser URI → provider + native connection string.
ZLinqResultExtensions Zero-alloc in-memory result helpers.

Seeding

Seeders populate initial database data once per seeder name. Each seeder's name is tracked in the __squidstd_seed_history table; a seeder runs only if its name does not yet exist in the history. The history row is written only after a successful run - if a seeder throws, it is retried at the next process start. A seeder exception aborts startup (fail-fast). The seed and history row are not wrapped in a transaction, so a seeder should tolerate running again over data it already wrote.

The history table is created during database service start when at least one seeder is registered, independent of whether AutoMigrate is on or off. Seeder names must be unique; the startup duplicate check is ordinal (case-sensitive), while the history-table lookup for a given seeder's name follows the database's collation.

Delegate seeder

Register an inline seeding callback with a unique name:

bootstrap.ConfigureServices(c =>
{
    c.RegisterDatabase();  // binds "database" config, runs seeders after init
    
    // Inline delegate seeder
    c.RegisterDatabaseSeeder("accounts.admin", async (database, ct) =>
    {
        await database.Orm.Insert(new User { Id = 1, Name = "Admin" }).ExecuteAffrowsAsync(ct);
    });
    
    return c;
});

Class seeder

Implement IDatabaseSeeder (which provides the name) and register it by type:

public sealed class AdminAccountSeeder : IDatabaseSeeder
{
    public string Name => "accounts.admin";
    
    public async ValueTask SeedAsync(IDatabaseService database, CancellationToken cancellationToken = default)
    {
        await database.Orm.Insert(new User { Id = 1, Name = "Admin" }).ExecuteAffrowsAsync(cancellationToken);
    }
}

bootstrap.ConfigureServices(c =>
{
    c.RegisterDatabase();
    c.RegisterDatabaseSeeder<AdminAccountSeeder>();
    
    return c;
});

Key semantics

  • Run-once per name: The __squidstd_seed_history table tracks which seeders have successfully run. A seeder is skipped if its name already exists in the history.
  • Failed-seeder retry: The history row is written only after the seeder succeeds. If a seeder throws, the row is not written, and the seeder retries at the next process start.
  • History table creation: The table is created during database service start when at least one seeder is registered (this is what triggers RunSeedersAsync), independent of whether AutoMigrate is on or off. Its schema is internal to SquidStd and should not be modified.
  • Duplicate name check: Seeder names must be unique. Duplicate names (ordinal, case-sensitive match) are detected at startup and cause an exception.
  • Execution order: Seeders run in registration order. Multiple seeders can be registered via chained RegisterDatabaseSeeder() calls.
  • No transaction wrap: The seed and its history row are not wrapped in a transaction. Seeders should be idempotent or accept re-running over partially-written state.

License

MIT - part of SquidStd.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.37.0 6 7/17/2026
0.36.0 84 7/15/2026
0.35.0 79 7/15/2026
0.34.0 83 7/14/2026
0.33.1 85 7/13/2026
0.33.0 88 7/13/2026
0.32.1 88 7/13/2026
0.32.0 90 7/13/2026
0.31.0 91 7/12/2026
0.30.0 89 7/12/2026
0.29.0 91 7/11/2026
0.28.0 92 7/8/2026
0.27.0 97 7/7/2026
0.26.0 86 7/7/2026
0.25.0 94 7/6/2026
0.24.1 97 7/6/2026
0.24.0 92 7/6/2026
0.23.0 91 7/4/2026
0.22.0 88 7/4/2026
0.21.0 93 7/3/2026
Loading failed