Documentation
¶
Overview ¶
Package postgres contains implementations of go-eventually interfaces specific to PostgreSQL, such as Aggregate Repository, Event Store, etc.
Index ¶
Constants ¶
const ( // DefaultAggregateTableName is the default aggregate snapshot table. DefaultAggregateTableName = "aggregates" // DefaultEventsTableName is the default domain events table. DefaultEventsTableName = "events" // DefaultStreamsTableName is the default event streams table. DefaultStreamsTableName = "event_streams" )
Variables ¶
var ErrTransactionRequired = errors.New("postgres.TransactionAwareAggregateRepository: transaction required but not found in context")
ErrTransactionRequired reports a missing transaction in context.
Functions ¶
func RunMigrations ¶
RunMigrations runs the latest migrations for the postgres integration.
Make sure to run these in the entrypoint of your application, ideally before building a postgres interface implementation.
Types ¶
type AggregateRepository ¶
type AggregateRepository[ID aggregate.ID, T aggregate.Root[ID]] struct { // contains filtered or unexported fields }
AggregateRepository implements aggregate.Repository for PostgreSQL. It reads aggregate snapshots from the pool and saves snapshots and recorded domain events together in a self-managed Serializable transaction. Table names can be configured using the available functional options.
func NewAggregateRepository ¶
func NewAggregateRepository[ID aggregate.ID, T aggregate.Root[ID]]( conn *pgxpool.Pool, aggregateType aggregate.Type[ID, T], aggregateSerde serde.Bytes[T], messageSerde serde.Bytes[message.Message], options ...Option[ID, T], ) AggregateRepository[ID, T]
NewAggregateRepository returns a new AggregateRepository instance.
type EventStore ¶
type EventStore struct {
// contains filtered or unexported fields
}
EventStore is an event.Store implementation targeted to PostgreSQL databases.
The implementation uses "event_streams" and "events" as their operational tables. Updates to these tables are transactional.
func NewEventStore ¶
NewEventStore returns a new EventStore instance.
type Option ¶
type Option[ID aggregate.ID, T aggregate.Root[ID]] interface { // contains filtered or unexported methods }
Option configures the shared implementation of PostgreSQL aggregate repositories.
func WithAggregateTableName ¶
WithAggregateTableName configures the aggregate snapshot table.
func WithEventsTableName ¶
WithEventsTableName configures the domain events table.
type TransactionAwareAggregateRepository ¶ added in v0.4.4
type TransactionAwareAggregateRepository[ID aggregate.ID, T aggregate.Root[ID]] struct { // contains filtered or unexported fields }
TransactionAwareAggregateRepository implements aggregate.Repository using caller-owned transactions for both reads and writes. It never begins, commits, or rolls back a transaction. Transactions must use Serializable isolation. Save success means writes are staged; the caller must commit the transaction. After a failed or rolled-back save, discard the aggregate and reload before retrying.
func NewTransactionAwareAggregateRepository ¶ added in v0.4.4
func NewTransactionAwareAggregateRepository[ID aggregate.ID, T aggregate.Root[ID]]( retrieveTx TxRetriever, aggregateType aggregate.Type[ID, T], aggregateSerde serde.Bytes[T], messageSerde serde.Bytes[message.Message], options ...Option[ID, T], ) TransactionAwareAggregateRepository[ID, T]
NewTransactionAwareAggregateRepository returns a repository requiring a transaction from retrieveTx for every operation.
func (TransactionAwareAggregateRepository[ID, T]) Get ¶ added in v0.4.4
func (repo TransactionAwareAggregateRepository[ID, T]) Get(ctx context.Context, id ID) (T, error)
Get reads an aggregate snapshot within the transaction retrieved from ctx. Returns ErrTransactionRequired if no transaction is available, or aggregate.ErrRootNotFound if the aggregate does not exist.
func (TransactionAwareAggregateRepository[ID, T]) Save ¶ added in v0.4.4
func (repo TransactionAwareAggregateRepository[ID, T]) Save(ctx context.Context, root T) error
Save writes the snapshot and recorded events within the transaction retrieved from ctx. Returns ErrTransactionRequired without flushing events if no transaction is available. The caller must roll back on error.