StringThing.Npgsql
1.0.0
See the version list below for details.
dotnet add package StringThing.Npgsql --version 1.0.0
NuGet\Install-Package StringThing.Npgsql -Version 1.0.0
<PackageReference Include="StringThing.Npgsql" Version="1.0.0" />
<PackageVersion Include="StringThing.Npgsql" Version="1.0.0" />
<PackageReference Include="StringThing.Npgsql" />
paket add StringThing.Npgsql --version 1.0.0
#r "nuget: StringThing.Npgsql, 1.0.0"
#:package StringThing.Npgsql@1.0.0
#addin nuget:?package=StringThing.Npgsql&version=1.0.0
#tool nuget:?package=StringThing.Npgsql&version=1.0.0
StringThing.Npgsql
Injection-safe interpolated SQL for PostgreSQL, built on Npgsql. Part of StringThing.
Install
dotnet add package StringThing.Npgsql
Quick start
var userId = 42;
PostgresSql stmt = $"SELECT name FROM users WHERE id = {userId}";
await using var command = stmt.ToCommand(dataSource);
Supported types
All standard .NET types (int, string, DateTime, Guid, etc.) plus Postgres-specific types: NpgsqlPoint, NpgsqlBox, NpgsqlRange<T>, NpgsqlTsVector, NpgsqlTsQuery, IPAddress, and more. See PostgresValue for the full list.
Nullable variants are supported. Reference types (string?, byte[]?, IPAddress?) map to NULL. Value types use PostgresValue?.
Fragments
var minAge = 18;
var status = "active";
PostgresFragment filter = $"age >= {minAge} AND status = {status}";
PostgresSql stmt = $"SELECT * FROM users WHERE {filter}";
Fragments compose. Parameters renumber automatically across fragment boundaries.
Multi-row insert
record InsertUser(int Id, string Name, string? Email) : IPostgresRow
{
public PostgresFragment RowValues => $"({Id}, {Name}, {Email})";
}
var users = new InsertUser[] { new(1, "alice", "alice@example.com"), new(2, "bob", null) };
PostgresSql stmt = $"INSERT INTO users (id, name, email) VALUES {PostgresSql.InsertRows(users)}";
JSON
Implement IPostgresJson on your types to store them as jsonb. Use your choice of serializer:
record UserData(string Name, int Age) : IPostgresJson
{
public string ToJson() => $$"""{"name":"{{Name}}","age":{{Age}}}""";
}
PostgresSql stmt = $"INSERT INTO data (payload) VALUES ({userData})";
Unsafe escape hatch
var tableName = Sql.Unsafe("users");
PostgresSql stmt = $"SELECT * FROM {tableName} WHERE id = {userId}";
Built by Immersus Machina
| Product | Versions 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. |
-
net10.0
- Npgsql (>= 9.0.0)
- StringThing.Core (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on StringThing.Npgsql:
| Package | Downloads |
|---|---|
|
StringThing.Npgsql.Dapper
Dapper result mapping for StringThing.Npgsql. Injection-safe interpolated SQL on input, Dapper mapping on output. Dapper is bundled internally. |
GitHub repositories
This package is not used by any popular GitHub repositories.