Suwbackkit.Postgres 0.4.0

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

Suwbackkit.Postgres

PostgreSQL for the backends of Manomenu's apps: one Npgsql data source, grate migrations when the server starts, and a health check.

  • Connection: ConnectionStrings:Default (user secrets, or ConnectionStrings__Default). With migrations on, a missing one stops the server at start with a message that says what to set.
  • NpgsqlDataSource: registered once, as Npgsql recommends; inject it and open connections from it. The pool defaults to Maximum Pool Size=5 and Keepalive=10; any parameter in the connection string overrides them.
  • Migrations: grate runs Database/Migrations/up/*.sql from the app's output folder in one transaction when the server starts. A script runs once; editing a script that already ran fails the migration; a failing script leaves nothing behind.
  • Health check database: SELECT 1, so /health and /api/health from Suwbackkit.Server answer 503 with "The database does not answer" when it is down. It does not run for /alive.

Usage

using Suwbackkit.Postgres;
using Suwbackkit.Server;

var builder = WebApplication.CreateBuilder(args);
builder.AddServerDefaults();
builder.Services.AddDatabase(builder.Configuration, migrateOnStart: !ServerDefaults.WritingOpenApiDocument);

var app = builder.Build();
app.MapServerDefaults();
app.Run();

Copy the migrations to the output folder in the app's .csproj:

<None Include="Database/Migrations/**" CopyToOutputDirectory="PreserveNewest" />

Query with the data source, for example with Dapper (the app's choice, not a dependency of this package):

internal sealed class NoteStore(NpgsqlDataSource dataSource)
{
    public async Task<IReadOnlyList<Note>> ListAsync(CancellationToken cancellationToken)
    {
        await using var connection = await dataSource.OpenConnectionAsync(cancellationToken);
        return [.. await connection.QueryAsync<Note>(new CommandDefinition("SELECT id, text FROM notes", cancellationToken: cancellationToken))];
    }
}

Tests migrate their own database with Migrator.MigrateAsync(connectionString, Migrator.DefaultDirectory).

Broken connections

A connection the database closed while it sat idle in the pool (a database restart, pg_terminate_backend) is not tested before it is handed out: Npgsql decided against a check on every open, because it costs a round trip each time and still races with the server (Npgsql FAQ). Instead Keepalive=10 pings idle connections every 10 seconds and drops the dead ones, so after a restart only work in that window can meet a closed connection, which then fails once and leaves the pool. Code that must survive that retries on NpgsqlException.IsTransient.

Source, license and changes: https://github.com/Manomenu/suwbackkit

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.5.2 81 11/22/2026
0.5.1 74 11/22/2026
0.5.0 81 11/21/2026
0.4.0 97 11/21/2026
0.3.0 71 11/21/2026
0.2.2 52 11/21/2026
0.2.1 65 11/21/2026
0.2.0 51 11/20/2026
0.1.0 128 11/20/2026