@sekiban/postgres
Version:
PostgreSQL storage provider for Sekiban Event Sourcing framework
79 lines (58 loc) • 1.93 kB
Markdown
> ⚠️ **Alpha Version**: This package is currently in alpha. APIs may change between releases.
PostgreSQL storage provider for Sekiban Event Sourcing framework.
```bash
npm install @sekiban/postgres@alpha @sekiban/core@alpha
pnpm add @sekiban/postgres@alpha @sekiban/core@alpha
yarn add @sekiban/postgres@alpha @sekiban/core@alpha
```
- Full PostgreSQL support for event storage
- Optimistic concurrency control
- Event streaming capabilities
- Snapshot support
- Multi-tenant support with partition keys
- Connection pooling with pg-pool
```typescript
import { createPostgresStorageProvider } from '@sekiban/postgres';
import { createSekibanExecutor } from '@sekiban/core';
// Create storage provider
const storageProvider = createPostgresStorageProvider({
connectionString: 'postgresql://user:pass@localhost:5432/sekiban',
maxRetries: 3,
retryDelayMs: 100
});
// Initialize storage
await storageProvider.initialize();
// Create executor with PostgreSQL storage
const executor = createSekibanExecutor({
storageProvider,
domainTypes: yourDomainTypes
});
// Use the executor
const result = await executor.executeCommand(command);
```
```typescript
interface PostgresStorageConfig {
connectionString: string; // PostgreSQL connection string
poolSize?: number; // Connection pool size (default: 10)
maxRetries?: number; // Max retry attempts (default: 3)
retryDelayMs?: number; // Delay between retries (default: 100ms)
schema?: string; // Database schema (default: 'public')
}
```
The provider will automatically create the required tables:
- `events` - Stores all domain events
- `snapshots` - Stores aggregate snapshots
- `projections` - Stores multi-projection states
- PostgreSQL 12 or higher
- Node.js 18 or higher
MIT