Delly.DBunny.PostgreSql 2026.5.7

dotnet add package Delly.DBunny.PostgreSql --version 2026.5.7
                    
NuGet\Install-Package Delly.DBunny.PostgreSql -Version 2026.5.7
                    
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="Delly.DBunny.PostgreSql" Version="2026.5.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Delly.DBunny.PostgreSql" Version="2026.5.7" />
                    
Directory.Packages.props
<PackageReference Include="Delly.DBunny.PostgreSql" />
                    
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 Delly.DBunny.PostgreSql --version 2026.5.7
                    
#r "nuget: Delly.DBunny.PostgreSql, 2026.5.7"
                    
#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 Delly.DBunny.PostgreSql@2026.5.7
                    
#: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=Delly.DBunny.PostgreSql&version=2026.5.7
                    
Install as a Cake Addin
#tool nuget:?package=Delly.DBunny.PostgreSql&version=2026.5.7
                    
Install as a Cake Tool

Delly.DBunny.PostgreSql

License .NET AOT Compatible

PostgreSQL provider implementation for DBunny. Also compatible with compatible databases like CockroachDB.

Installation

dotnet add package Delly.DBunny.PostgreSql

Quick Start

using Delly.DBunny;
using Delly.DBunny.PostgreSql;
using Delly.DBunny.Sql.Extension;
using Delly.DBunny.Connecting.Extension;
using System.Data.Common;

// Create connection using builder
var connectionDefine = new PostgreSqlConnectionDefine()
    .WithHost("localhost")
    .WithPort(5432)
    .WithDatabase("mydb")
    .WithUsername("postgres")
    .WithPassword("password");

var descriptor = connectionDefine.GetDbConnectionDescriptor(
    PostgreSqlConnectionDefine.DATABASE_TYPE, "Default");

var provider = new PostgreSqlProvider();
using var connection = provider.GetDbConnection(descriptor.ConnectionString);
connection.Open();

// Create a table in public schema
var columnDescriptors = new List<DbColumnDesciptor>
{
    new DbColumnDesciptor { ColumnName = "Id", ColumnType = "INTEGER", PrimaryKeyFlag = true, NullableFlag = false },
    new DbColumnDesciptor { ColumnName = "Name", ColumnType = "VARCHAR(100)", PrimaryKeyFlag = false, NullableFlag = false },
    new DbColumnDesciptor { ColumnName = "Age", ColumnType = "INTEGER", PrimaryKeyFlag = false, NullableFlag = true }
};
var createTableSql = provider.SqlProvider.CreateTable("public", "Users", columnDescriptors);

using var createCommand = provider.GetDbCommand(connection);
createCommand.CommandText = createTableSql.Sql;
await createCommand.ExecuteNonQueryAsync();

// Insert data
var insertSql = new Sqled("INSERT INTO \"public\".\"Users\" (Name, Age) VALUES (@name, @age)")
    .Set("name", "John Doe")
    .Set("age", 30);

using var insertCommand = provider.GetDbCommand(connection);
insertCommand.CommandText = insertSql.Sql;
provider.SetParameters(insertCommand, insertSql.Parameters);
await insertCommand.ExecuteNonQueryAsync();

// Query data
var selectSql = new Sqled("SELECT * FROM \"public\".\"Users\" WHERE Age > @minAge")
    .Set("minAge", 18);

await provider.ReadAsync(connection, selectSql, async reader =>
{
    while (await reader.ReadAsync())
    {
        var id = reader["Id"];
        var name = reader["Name"];
        var age = reader["Age"];
        Console.WriteLine($"Id: {id}, Name: {name}, Age: {age}");
    }
});

Connection Builder

Use the fluent builder for connection configuration:

using Delly.DBunny.PostgreSql;
using Delly.DBunny.Connecting.Extension;

var connectionDefine = new PostgreSqlConnectionDefine()
    .WithHost("localhost")
    .WithPort(5432)
    .WithDatabase("mydb")
    .WithUsername("postgres")
    .WithPassword("password")
    .WithSearchPath("public")
    .WithSslMode("Prefer")
    .WithTrustServerCertificate(false)
    .WithTimeout(30)
    .WithCommandTimeout(600)
    .WithPooling(true)
    .WithMinPoolSize(0)
    .WithMaxPoolSize(100);

var descriptor = connectionDefine.GetDbConnectionDescriptor(
    PostgreSqlConnectionDefine.DATABASE_TYPE, "Default");

Connection Parameters

Parameter Default Description
Host localhost PostgreSQL server host
Port 5432 PostgreSQL server port
Database - Database name
Username - Username
Password - Password
Search Path public Schema search path (comma-separated)
SSL Mode Prefer SSL mode (Disable, Allow, Prefer, Require, VerifyCA, VerifyFull)
Trust Server Certificate False Trust server certificate
Timeout 30 Connection timeout in seconds
Command Timeout 600 Command timeout in seconds
Pooling True Enable connection pooling
Minimum Pool Size 0 Minimum pool size
Maximum Pool Size 100 Maximum pool size

PostgreSQL Features

  • Database Layer: Full database support
  • Schema Layer: Full schema support (default: public)
  • Name Quoting: Uses double quotes "name"
  • Parameter Prefix: @
  • Serial Types: Uses SERIAL/BIGSERIAL for auto-incrementing columns
  • Type Mapping:
    • Boolean → BOOLEAN
    • Byte, SByte → SMALLINT
    • Int16, UInt16 → SMALLINT
    • Int32, UInt32 → INTEGER
    • Int64, UInt64 → BIGINT
    • Single → REAL
    • Double → DOUBLE PRECISION
    • Decimal → NUMERIC
    • DateTime → TIMESTAMP
    • String (<=65535 chars) → VARCHAR
    • String (>65535 chars) → TEXT

Schema Operations

PostgreSQL supports schema creation and management:

// Create a schema
var createSchemaSql = provider.SqlProvider.CreateSchema("myschema", null!);
await ExecuteNonQueryAsync(connection, createSchemaSql);

// Get all schemas
var getSchemasSql = provider.SqlProvider.GetSchemas();
await provider.ReadAsync(connection, getSchemasSql, async reader =>
{
    while (await reader.ReadAsync())
    {
        var schemaName = reader.GetString(0);
        Console.WriteLine($"Schema: {schemaName}");
    }
});

// Drop a schema
var dropSchemaSql = provider.SqlProvider.DropSchema("myschema");
await ExecuteNonQueryAsync(connection, dropSchemaSql);

Search Path

The search path determines which schemas are searched for unqualified objects:

// Set multiple search paths
connectionDefine.WithSearchPath("public,myschema,other_schema");

SSL Mode Options

  • Disable: No SSL
  • Allow: Allow SSL but don't require it
  • Prefer: Try SSL first, fall back to non-SSL (default)
  • Require: SSL required (but certificate not verified)
  • VerifyCA: SSL required and certificate authority verified
  • VerifyFull: SSL required with full certificate verification

CockroachDB Compatibility

This provider also works with CockroachDB using the same connection parameters, as CockroachDB is PostgreSQL wire protocol compatible.

Dependencies

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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 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 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. 
.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

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
2026.5.7 100 5/19/2026
2026.5.6 96 5/19/2026
2026.5.5 99 5/18/2026
2026.5.4 99 5/18/2026
2026.5.3 105 5/18/2026
2026.5.2 96 5/17/2026