Skip to main content

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 8.0+ (or .NET 9/10 for latest features)
  • 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

MethodWhat It RegistersKey Options
AddPostgresDataExecutors(factory)Core data executorsConnection factory
AddPostgresEventStore(opts)IEventStoreConnectionString, SchemaName
AddPostgresSnapshotStore(opts)ISnapshotStoreConnectionString
AddPostgresInboxStore(opts)IInboxStoreConnectionString
AddPostgresProjectionStore<T>(opts)IProjectionStore<T>ConnectionString, TableName
AddPostgresCdc(opts)CDC processorConnectionString, PublicationName, ReplicationSlotName

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.AddPostgresCdc(options =>
{
options.ConnectionString = connectionString;
options.PublicationName = "my_publication";
options.ReplicationSlotName = "my_slot";
});

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