mvdmio.Database.PgSQL
0.24.0
See the version list below for details.
dotnet add package mvdmio.Database.PgSQL --version 0.24.0
NuGet\Install-Package mvdmio.Database.PgSQL -Version 0.24.0
<PackageReference Include="mvdmio.Database.PgSQL" Version="0.24.0" />
<PackageVersion Include="mvdmio.Database.PgSQL" Version="0.24.0" />
<PackageReference Include="mvdmio.Database.PgSQL" />
paket add mvdmio.Database.PgSQL --version 0.24.0
#r "nuget: mvdmio.Database.PgSQL, 0.24.0"
#:package mvdmio.Database.PgSQL@0.24.0
#addin nuget:?package=mvdmio.Database.PgSQL&version=0.24.0
#tool nuget:?package=mvdmio.Database.PgSQL&version=0.24.0
mvdmio.Database.PgSQL
PostgreSQL access for .NET applications.
The package combines Dapper and Npgsql with a higher-level API for common PostgreSQL workflows.
Installation
dotnet add package mvdmio.Database.PgSQL
Targets net8.0, net9.0, and net10.0.
What You Can Do With It
- Run SQL queries and commands through
db.Dapper - Execute work inside transactions
- Bulk insert or upsert rows
- Check schema and table existence
- Export the current database schema
- Limit schema export to selected PostgreSQL schemas when using the companion CLI configuration
- Preserve identity columns and stored generated columns during schema export
- Run migrations from application code
- Generate repositories from annotated table models
- Auto-embed
Schemas/**/*.sqlfiles for direct and transitive project references
Quick Start
using mvdmio.Database.PgSQL;
await using var db = new DatabaseConnection(
"Host=localhost;Database=mydb;Username=postgres;Password=secret"
);
var users = await db.Dapper.QueryAsync<User>(
"SELECT * FROM users WHERE active = :active",
new Dictionary<string, object?> { ["active"] = true }
);
await db.Dapper.ExecuteAsync(
"INSERT INTO users (name, email) VALUES (:name, :email)",
new Dictionary<string, object?>
{
["name"] = "Alice",
["email"] = "alice@example.com"
}
);
Common Usage
Transactions
await db.InTransactionAsync(async () =>
{
await db.Dapper.ExecuteAsync(
"INSERT INTO orders (customer_id, total) VALUES (:customerId, :total)",
new Dictionary<string, object?>
{
["customerId"] = 42,
["total"] = 99.95m
}
);
});
Bulk Operations
var mapping = new Dictionary<string, Func<Product, DbValue>>
{
["sku"] = x => x.Sku,
["name"] = x => x.Name,
["price"] = x => x.Price
};
await db.Bulk.CopyAsync("products", products, mapping);
For streaming COPY sessions, prefer await using so failed writes still dispose the importer and release the connection:
await using var session = await db.Bulk.BeginCopyAsync<Product>("products", mapping);
foreach (var product in products)
await session.WriteAsync(product);
await session.CompleteAsync();
Migrations In Code
using mvdmio.Database.PgSQL.Migrations;
var migrator = new DatabaseMigrator(db, typeof(Program).Assembly);
await migrator.MigrateDatabaseToLatestAsync();
Embedded Schema Files
When a project references mvdmio.Database.PgSQL directly, or references another project that does, any Schemas/**/*.sql files in that project are automatically included as embedded resources.
This works through the package's build and buildTransitive MSBuild props files.
Generated Repositories
using mvdmio.Database.PgSQL.Attributes;
[Table("public.users")]
public partial class UserTable
{
[PrimaryKey]
[Generated]
public long UserId { get; set; }
[Unique]
public string UserName { get; set; } = string.Empty;
}
From that model, the package generates repository types and CRUD command/data types you can use in application code.
CLI Tool
If you want a command-line workflow for migrations and schema files, install the companion tool:
dotnet tool install --global mvdmio.Database.PgSQL.Tool
See ../mvdmio.Database.PgSQL.Tool/README.md.
License
MIT. See ../../LICENSE.
| 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
- Dapper (>= 2.1.66)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Npgsql (>= 10.0.1)
- Portable.System.DateTimeOnly (>= 9.0.1)
-
net8.0
- Dapper (>= 2.1.66)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Npgsql (>= 10.0.1)
- Portable.System.DateTimeOnly (>= 9.0.1)
-
net9.0
- Dapper (>= 2.1.66)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Npgsql (>= 10.0.1)
- Portable.System.DateTimeOnly (>= 9.0.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on mvdmio.Database.PgSQL:
| Package | Downloads |
|---|---|
|
mvdmio.ASP.Jobs
Job scheduling library for use in ASP.NET projects. |
|
|
mvdmio.HealthCheck.Client
Client library for mvdm.io HealthCheck. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.26.1 | 0 | 6/5/2026 |
| 0.26.0 | 254 | 4/27/2026 |
| 0.25.0 | 355 | 4/19/2026 |
| 0.24.1 | 98 | 4/16/2026 |
| 0.24.0 | 99 | 4/15/2026 |
| 0.23.14 | 342 | 4/14/2026 |
| 0.23.13 | 96 | 4/14/2026 |
| 0.23.12 | 91 | 4/14/2026 |
| 0.23.11 | 91 | 4/14/2026 |
| 0.23.9 | 103 | 4/14/2026 |
| 0.23.8 | 115 | 4/11/2026 |
| 0.23.7 | 100 | 4/11/2026 |
| 0.23.5 | 94 | 4/9/2026 |
| 0.23.4 | 95 | 4/9/2026 |
| 0.23.0 | 98 | 4/9/2026 |
| 0.22.2 | 245 | 4/1/2026 |
| 0.22.0 | 121 | 3/26/2026 |
| 0.21.0 | 212 | 3/24/2026 |
| 0.20.0 | 113 | 3/11/2026 |
| 0.19.3 | 112 | 3/11/2026 |