PostgreSQL Provider
The PostgreSQL provider offers full relational database support with Npgsql-based query execution, event sourcing integration, inbox/outbox patterns, and Change Data Capture.
Before You Start
- .NET 10.0
- A PostgreSQL instance (local or cloud-hosted)
- Familiarity with data access and IDb interface
Installation
dotnet add package Excalibur.Data.Postgres
Dependencies: Excalibur.Data.Abstractions, Npgsql
Quick Start
using Microsoft.Extensions.DependencyInjection;
services.AddPostgresDataExecutors(() => new NpgsqlConnection(connectionString));
Registration Methods
| Method | What It Registers | Key Options |
|---|---|---|
data.UsePostgres(Action<IPostgresDataBuilder>) | Core data executors | Builder with 5 connection overloads |
es.UsePostgres(Action<IPostgresEventSourcingBuilder>) | IEventStore + ISnapshotStore | Builder with 5 connection overloads |
saga.UsePostgres(Action<IPostgresSagaBuilder>) | ISagaStore | Builder with 5 connection + SchemaName, TableName |
inbox.UsePostgres(Action<IPostgresInboxBuilder>) | IInboxStore | Builder with 5 connection + SchemaName, TableName, MaxRetryCount |
outbox.UsePostgres(Action<IPostgresOutboxBuilder>) | IOutboxStore | Builder with 5+ connection + SchemaName, TableName, DeadLetterTableName |
le.UsePostgres(Action<IPostgresLeaderElectionBuilder>) | ILeaderElection | Builder with 5 connection + LockKey |
cdc.UsePostgres(Action<IPostgresCdcBuilder>) | CDC processor | Builder with 5 connection + PublicationName, ReplicationSlotName |
compliance.UsePostgres(Action<IPostgresComplianceBuilder>) | Erasure + DataInventory + LegalHold | Builder with 5 connection overloads |
audit.UsePostgres(Action<IPostgresAuditLoggingBuilder>) | IAuditStore | Builder with 5 connection + SchemaName, TableName |
AddPostgresProjectionStore<T>(opts) | IProjectionStore<T> | ConnectionString, TableName |
Batch Projection Registration
Register multiple projections sharing the same connection:
services.AddPostgresProjections(connectionString, projections =>
{
projections.Add<OrderSummary>();
projections.Add<CustomerProfile>(o => o.TableName = "customer_views");
});
Change Data Capture
services.AddCdcProcessor(cdc =>
{
cdc.UsePostgres(pg => pg.ConnectionString(connectionString))
.TrackTable("public.orders", t => t.MapAll<OrderChangedEvent>());
});
Data Request Pattern
public class GetCustomerRequest : DataRequest<Customer?>
{
public GetCustomerRequest(Guid customerId)
{
Command = new CommandDefinition(
"SELECT * FROM customers WHERE id = @Id",
new { Id = customerId });
}
}
See Also
- Data Providers Overview — Architecture and core abstractions
- SQL Server Provider — Microsoft SQL Server alternative
- Event Sourcing — PostgreSQL event store integration