Pinqponq.Database.Postgres
1.0.1
Prefix Reserved
dotnet add package Pinqponq.Database.Postgres --version 1.0.1
NuGet\Install-Package Pinqponq.Database.Postgres -Version 1.0.1
<PackageReference Include="Pinqponq.Database.Postgres" Version="1.0.1" />
<PackageVersion Include="Pinqponq.Database.Postgres" Version="1.0.1" />
<PackageReference Include="Pinqponq.Database.Postgres" />
paket add Pinqponq.Database.Postgres --version 1.0.1
#r "nuget: Pinqponq.Database.Postgres, 1.0.1"
#:package Pinqponq.Database.Postgres@1.0.1
#addin nuget:?package=Pinqponq.Database.Postgres&version=1.0.1
#tool nuget:?package=Pinqponq.Database.Postgres&version=1.0.1
Pinqponq.Database.Postgres
A minimal, opinionated PostgreSQL connection layer for .NET: a shared
NpgsqlDataSource, a retrying connection factory (IPostgresConnectionFactory),
and a ready-made health check. It deliberately stops at "give me an open
connection" — no repository base classes, no entity mapping, no query
builder. What you do with the connection is up to you (raw ADO.NET, Dapper,
EF Core, etc.).
Install
dotnet add package Pinqponq.Database.Postgres
Requirements
- .NET SDK:
net8.0,net9.0, ornet10.0 - A reachable PostgreSQL server
Npgsql(pulled in transitively)
Quick start
using Pinqponq.Database.Postgres;
using Pinqponq.Database.Postgres.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddPinqponqPostgres(postgres =>
{
postgres.ConnectionString = builder.Configuration.GetConnectionString("Postgres")!;
postgres.RetryCount = 3;
postgres.RetryBaseDelay = TimeSpan.FromMilliseconds(200);
});
builder.Services.AddHealthChecks().AddPinqponqPostgres();
var app = builder.Build();
app.MapGet("/version", async (IPostgresConnectionFactory factory, CancellationToken ct) =>
{
await using var connection = await factory.OpenConnectionAsync(ct);
await using var command = connection.CreateCommand();
command.CommandText = "SELECT version()";
return await command.ExecuteScalarAsync(ct);
});
app.Run();
Using the factory from an injected service:
public sealed class ReportRepository(IPostgresConnectionFactory factory)
{
public async Task<int> CountOrdersAsync(CancellationToken ct)
{
await using var connection = await factory.OpenConnectionAsync(ct);
await using var command = connection.CreateCommand();
command.CommandText = "SELECT count(*) FROM orders";
var result = await command.ExecuteScalarAsync(ct);
return Convert.ToInt32(result);
}
}
Configuration
PostgresOptions, configured through the Action<PostgresOptions> delegate
passed to AddPinqponqPostgres:
| Property | Type | Default | Notes |
|---|---|---|---|
ConnectionString |
string |
"" (required) |
Standard Npgsql connection string. |
RetryCount |
int |
3 |
Maximum retry attempts on transient failures. Must not be negative. 0 is valid for the options but note that Polly's retry pipeline itself may reject MaxRetryAttempts = 0 depending on configuration — prefer 1 or higher for real resiliency. |
RetryBaseDelay |
TimeSpan |
200ms |
Base delay for exponential backoff between retries (with jitter). Must be positive. |
Options are validated at startup via ValidateOnStart().
Main types
| Type | Kind | Purpose |
|---|---|---|
AddPinqponqPostgres(Action<PostgresOptions>) |
DI extension (IServiceCollection) |
Registers a shared NpgsqlDataSource and an IPostgresConnectionFactory with retry resiliency. |
AddPinqponqPostgres(...) |
DI extension (IHealthChecksBuilder) |
Adds a SELECT 1 health check (name defaults to "postgres") that opens its own connection from the shared data source, bypassing the retry pipeline. |
IPostgresConnectionFactory |
Interface | OpenConnectionAsync(ct) → NpgsqlConnection, retrying transient failures per PostgresOptions. |
PostgresOptions |
Options | Connection string and retry configuration. |
PostgresConnectionFactory, PostgresHealthCheck |
Implementations | Registered by the extension methods; not usually referenced directly. |
Notes / behavior
- Shared data source.
AddPinqponqPostgresregisters a singleNpgsqlDataSourcesingleton built fromConnectionStringviaNpgsqlDataSource.Create(...), and bothIPostgresConnectionFactoryand the health check pull connections from it — pooling is handled by Npgsql itself, not duplicated by this package. - Retry classification. The factory wraps
NpgsqlDataSource.OpenConnectionAsyncin a PollyResiliencePipelinethat retriesNpgsqlExceptionwhenIsTransientistrueand anyTimeoutException, using exponential backoff with jitter. Non-transient errors (e.g. bad credentials, syntax errors surfaced during connection setup) are not retried and propagate immediately. - Health check bypasses retry.
PostgresHealthCheckopens a connection directly from the sharedNpgsqlDataSourceand runsSELECT 1— it does not go throughIPostgresConnectionFactory's retry pipeline, so a single failed attempt is enough to reportUnhealthy. This is intentional: health checks should reflect current reachability, not retry-smoothed reachability. - No repositories, no entities. This package only opens connections. Data access patterns, table mapping, and migrations are entirely up to the consuming application.
Related packages
Samples
Try this package in the browser via Pinqponq.Playground — see samples/README.md.
Repository
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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 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. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.10)
- Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options (>= 10.0.10)
- Npgsql (>= 8.0.5)
- Polly.Core (>= 8.4.2)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.11)
- Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions (>= 8.0.11)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- Microsoft.Extensions.Options (>= 8.0.2)
- Npgsql (>= 8.0.5)
- Polly.Core (>= 8.4.2)
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.18)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.18)
- Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions (>= 9.0.18)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.18)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.18)
- Microsoft.Extensions.Options (>= 9.0.18)
- Npgsql (>= 8.0.5)
- Polly.Core (>= 8.4.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.