CodeLogic.PostgreSQL
4.6.72
dotnet add package CodeLogic.PostgreSQL --version 4.6.72
NuGet\Install-Package CodeLogic.PostgreSQL -Version 4.6.72
<PackageReference Include="CodeLogic.PostgreSQL" Version="4.6.72" />
<PackageVersion Include="CodeLogic.PostgreSQL" Version="4.6.72" />
<PackageReference Include="CodeLogic.PostgreSQL" />
paket add CodeLogic.PostgreSQL --version 4.6.72
#r "nuget: CodeLogic.PostgreSQL, 4.6.72"
#:package CodeLogic.PostgreSQL@4.6.72
#addin nuget:?package=CodeLogic.PostgreSQL&version=4.6.72
#tool nuget:?package=CodeLogic.PostgreSQL&version=4.6.72
CodeLogic.PostgreSQL
A typed PostgreSQL data-access layer for CodeLogic 4 — multi-database connections, an attribute-driven repository, a fluent LINQ query builder, transactions, and declarative schema sync with backups and migration tracking.
Map a plain class with attributes and the library reconciles the live table to match, then exposes a typed Repository<T> and a chainable QueryBuilder<T> over it. It builds on Npgsql and connects to one or many PostgreSQL instances from a single config. Every fallible operation returns a framework Result<T> — no exceptions on the expected failure paths.
Install
dotnet add package CodeLogic.PostgreSQL
Quick start
using CL.PostgreSQL;
using CL.PostgreSQL.Models;
await Libraries.LoadAsync<PostgreSQLLibrary>(); // register before ConfigureAsync()
await CodeLogic.ConfigureAsync();
await CodeLogic.StartAsync();
var pg = Libraries.Get<PostgreSQLLibrary>();
// Define an entity
[Table(Name = "users", Schema = "public")]
public class User
{
[Column(Primary = true, AutoIncrement = true)] public int Id { get; set; }
[Column(NotNull = true)] public string Name { get; set; } = "";
[Column] public bool IsActive { get; set; }
}
// 1. Reconcile the table to match the entity (creates it, or adds missing columns/indexes)
Result<SyncResult> sync = await pg.SyncTableAsync<User>();
// 2. Typed repository CRUD
var repo = pg.GetRepository<User>();
Result<User> created = await repo.InsertAsync(new User { Name = "Ada", IsActive = true });
// 3. Fluent query builder
Result<List<User>> users = await pg.Query<User>()
.Where(u => u.IsActive)
.OrderBy(u => u.Name)
.Limit(50)
.ToListAsync();
Features
- Multi-database — manage connections to several PostgreSQL instances from one config; pick the target per call with a
connectionId(default"Default"), orRegisterDatabaseone at runtime. - Repository pattern —
GetRepository<T>()for full CRUD plus bulk insert, paging, find, raw SQL, and atomic increment/decrement. - Fluent query builder —
Query<T>()withWhere,OrderBy/OrderByDescending,Limit/Offset(aliasesTake/Skip),Join,Select,GroupBy, aggregates, paging, and bulk update/delete. - Attribute-driven schema —
[Table],[Column],[ForeignKey],[CompositeIndex],[Ignore]map a plain class to a real table. - Schema sync & migrations — create or alter tables to match entities (single, set, or whole namespace), with timestamped schema backups and a JSON migration history.
- Transactions —
BeginTransactionAsync()returns anawait usingscope that auto-rolls-back if it is never committed. - Health checks & events —
HealthCheckAsync()plus events for connect/disconnect, table sync, slow query, and health changes.
Configuration
Auto-generated on first run as config.postgresql.json (section postgresql). Databases is a named map keyed by connection id; Default is created automatically.
{
"Databases": {
"Default": {
"Enabled": true,
"Host": "localhost",
"Port": 5432,
"Database": "mydb",
"Username": "postgres",
"Password": "",
"ConnectionTimeout": 30,
"CommandTimeout": 30,
"MinPoolSize": 5,
"MaxPoolSize": 100,
"MaxIdleTime": 60,
"SslMode": "Prefer",
"AllowDestructiveSync": false,
"SlowQueryThresholdMs": 1000
}
}
}
| Setting | Default | Description |
|---|---|---|
Enabled |
true |
Per-database switch; disabled databases are skipped at startup. |
Host / Port |
localhost / 5432 |
Server endpoint. |
Database / Username / Password |
"" |
Connection credentials. |
ConnectionTimeout |
30 |
Seconds to wait when opening a connection. |
CommandTimeout |
30 |
Seconds before a command times out. |
MinPoolSize / MaxPoolSize |
5 / 100 |
Connection-pool bounds. |
MaxIdleTime |
60 |
Seconds an idle pooled connection is kept before being closed. |
SslMode |
Prefer |
Disable, Allow, Prefer, Require, VerifyCA, or VerifyFull. |
AllowDestructiveSync |
false |
Dev-only; allows DROP operations during schema sync. |
SlowQueryThresholdMs |
1000 |
Queries at or above this duration raise a SlowQueryEvent. |
Documentation
Full guide: CL.PostgreSQL documentation
- Overview — load, multi-database, repository CRUD, config, health, events.
- Query Builder — fluent methods, terminals, aggregates, bulk writes, raw SQL, transactions.
- Schema & Sync — entity attributes, table & namespace sync, backups, migration tracker.
Requirements
- CodeLogic 4 · .NET 10
- Npgsql 9.x · PostgreSQL 12+
License
MIT — see LICENSE.
| 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. |
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 |
|---|---|---|
| 4.6.72 | 43 | 6/20/2026 |
| 4.6.69-preview | 32 | 6/20/2026 |
| 4.5.2 | 105 | 5/24/2026 |
| 4.5.2-preview.68 | 61 | 6/20/2026 |
| 4.5.1 | 104 | 5/24/2026 |
| 4.5.1-preview.56 | 54 | 5/24/2026 |
| 4.4.2-preview.53 | 62 | 5/24/2026 |
| 4.4.1 | 102 | 5/24/2026 |
| 4.0.5 | 101 | 5/15/2026 |
| 4.0.4 | 110 | 5/9/2026 |
| 4.0.3 | 111 | 5/9/2026 |
| 3.3.1 | 112 | 4/18/2026 |
| 3.3.0 | 116 | 4/18/2026 |
| 3.2.11 | 106 | 4/18/2026 |
| 3.2.10 | 108 | 4/18/2026 |
| 3.2.9 | 106 | 4/18/2026 |
| 3.2.8 | 106 | 4/18/2026 |
| 3.2.7 | 101 | 4/18/2026 |
| 3.2.6 | 102 | 4/18/2026 |
| 3.2.5 | 107 | 4/18/2026 |
# CL.PostgreSQL — Changelog
All notable changes to **CodeLogic.PostgreSQL** are documented here. Versions follow
[Semantic Versioning](https://semver.org/).
## 2026-06-20
### Fixed
- Query-builder parameter re-keying could corrupt SQL when a predicate emitted
11+ parameters (`@p1` substring-collided with `@p10`/`@p11`); parameters are
now renamed longest-name-first.
- The expression translator wiped the entire WHERE buffer for a `null == x.Prop`
comparison (it called `_sql.Clear()`), producing malformed SQL when combined
with other clauses; null comparisons in both operand orders now translate to
`IS [NOT] NULL` without discarding accumulated SQL.
### Documentation
- Full README rewrite to the unified house style: concise NuGet + MIT badges,
one-line tagline, `Install` / `Quick start` / `Features` / `Configuration`
(table + JSON) / `Documentation` / `Requirements` / `License`, with the API
detail moved to the docs site (no full API dump in the README).
- Replaced the single `docs/libs/postgresql.md` guide with a three-page docs set
mirroring CL.MySQL2's depth model: **Overview** (load, multi-database,
repository CRUD, entry points, config, health, events), **Query Builder**
(fluent methods, terminals, aggregates, bulk update/delete, raw SQL via
`QueryRaw`/repository raw, transactions), and **Schema & Sync** (entity
attributes, the `DataType` enum, table/set/namespace sync, `SyncResult`,
schema backups, the migration tracker).
- The old `docs/libs/postgresql.md` is now a thin redirect to the new Overview.
- No API changes — documentation only.
## [4.5.2] — 2026-06-20
### Documentation
- Documented the full **query builder** surface: `OrderByDescending`, `Limit`/`Offset`
(and `Take`/`Skip` aliases), `Join`, `Select`, `GroupBy`, `WithConnection`,
`ToPagedListAsync`, `FirstOrDefaultAsync`, the `CountAsync`/`MaxAsync`/`MinAsync`/
`SumAsync`/`AverageAsync` aggregates, and bulk `UpdateAsync`/`DeleteAsync`. Earlier
docs listed only `Where`/`OrderBy`/`ToListAsync`.
- Documented raw SQL access via `QueryRaw()` (`QueryAsync`/`ExecuteAsync`).
- Documented the **repository** beyond basic CRUD: `InsertManyAsync`, `GetByColumnAsync`,
`GetPagedAsync`, `FindAsync`, `IncrementAsync`/`DecrementAsync`, and
`RawQueryAsync`/`RawExecuteAsync`.
- Documented the schema attributes `[Table]`, `[Column]`, `[ForeignKey]`,
`[CompositeIndex]`, and `[Ignore]`, plus the `DataType` enum.
- Documented **table sync / migrations**: `SyncTablesAsync`, `SyncNamespaceAsync`,
`SyncResult`, the `BackupManager` (schema backups + cleanup), and the
`MigrationTracker` JSON history.
- Documented **transactions** via `BeginTransactionAsync` (auto-rollback on dispose).
- Documented previously-omitted configuration: `MaxIdleTime`, `AllowDestructiveSync`,
multi-database `connectionId` selection, and runtime `RegisterDatabase`.
### Notes
- The 4.0.0 "repository CRUD only" note is superseded — the query builder
(joins, aggregation, paging, bulk update/delete) is present and now documented.
## [4.5.0] — 2026-05-24
### Changed
- **Unified versioning.** All CodeLogic.Libs now share a single version line
controlled by `version.txt` in the repo root. This is a version alignment
release — no functional changes to this library.
## [4.0.4] — 2026-04-16
### Changed
- README + manifest refresh for the v4 baseline. No functional changes vs 4.0.3.
- `LibraryManifest.Version` now reads from assembly metadata.
## [4.0.2] — 2026-04-09
### Changed
- Annotated PostgreSQL configuration with `[ConfigField]` for the admin UI surface.
- Aligned with the v4 baseline across all libraries.
## [4.0.0] — 2026-04-09
Major rewrite. Republished as v4.0.0 to reset the version line under the
unified v4 baseline. Repository pattern + attribute-driven schema sync,
mirroring the CL.MySQL2 surface.
### Notes
- The MySQL2 4.0 query-builder rewrite (projection pushdown, SQL aggregation,
smart-cache pools) has not been ported to CL.PostgreSQL yet — repository
CRUD only.
- Earlier history is retained in the
[git log](https://github.com/Media2A/CodeLogic.Libs/commits/main/CL.PostgreSQL).