Documentation
¶
Overview ¶
Package projections implements Dogma projection handlers that build the read-models used by the UI.
These projections serve the web interface only and do not contain any business logic. They are implemented using the SQL adapter from projectionkit, a companion library for Dogma that simplifies building projection handlers for various backing stores. The SQL adapter manages transaction handling, offset tracking and idempotency, so each handler only needs to provide the SQL statements that update the read-model tables.
Index ¶
- func CreateSchema(ctx context.Context, db *sql.DB) error
- func MustNewDB() *sql.DB
- func NewDB() (*sql.DB, error)
- type CustomerProjectionHandler
- func (h *CustomerProjectionHandler) Configure(c dogma.ProjectionConfigurer)
- func (h *CustomerProjectionHandler) HandleEvent(ctx context.Context, tx *sql.Tx, _ dogma.ProjectionEventScope, m dogma.Event) error
- func (h *CustomerProjectionHandler) Reset(ctx context.Context, tx *sql.Tx, _ dogma.ProjectionResetScope) error
- type LedgerProjectionHandler
- func (h *LedgerProjectionHandler) Configure(c dogma.ProjectionConfigurer)
- func (h *LedgerProjectionHandler) HandleEvent(ctx context.Context, tx *sql.Tx, s dogma.ProjectionEventScope, m dogma.Event) error
- func (h *LedgerProjectionHandler) Reset(ctx context.Context, tx *sql.Tx, _ dogma.ProjectionResetScope) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateSchema ¶
CreateSchema creates the schema elements required by the projection handlers.
Types ¶
type CustomerProjectionHandler ¶
type CustomerProjectionHandler struct {
sqlprojection.NoCompactBehavior
}
CustomerProjectionHandler maintains a list of the bank's customers.
The UI queries the customers table to populate the login page, which simply lets the user pick an existing customer rather than performing any real authentication. It is also used to display the customer's name throughout the interface.
func (*CustomerProjectionHandler) Configure ¶
func (h *CustomerProjectionHandler) Configure(c dogma.ProjectionConfigurer)
Configure configs the engine for this projection.
func (*CustomerProjectionHandler) HandleEvent ¶
func (h *CustomerProjectionHandler) HandleEvent( ctx context.Context, tx *sql.Tx, _ dogma.ProjectionEventScope, m dogma.Event, ) error
HandleEvent inserts into the "customers" table whenever the bank acquires a new customer.
func (*CustomerProjectionHandler) Reset ¶
func (h *CustomerProjectionHandler) Reset( ctx context.Context, tx *sql.Tx, _ dogma.ProjectionResetScope, ) error
Reset clears all projection data.
type LedgerProjectionHandler ¶
type LedgerProjectionHandler struct {
sqlprojection.NoCompactBehavior
}
LedgerProjectionHandler maintains account balances and a ledger of transactions against each account.
It handles both the accounts and ledger tables within a single projection to ensure the running balance recorded on each ledger entry is consistent with the account balance.
The UI queries the accounts table to list a customer's accounts and their balances, and the ledger table to display transaction history.
func (*LedgerProjectionHandler) Configure ¶
func (h *LedgerProjectionHandler) Configure(c dogma.ProjectionConfigurer)
Configure configs the engine for this projection.
func (*LedgerProjectionHandler) HandleEvent ¶
func (h *LedgerProjectionHandler) HandleEvent( ctx context.Context, tx *sql.Tx, s dogma.ProjectionEventScope, m dogma.Event, ) error
HandleEvent inserts into the "ledger" table whenever an account is credited or debited, and updates the "accounts" table to reflect the current balance.
func (*LedgerProjectionHandler) Reset ¶
func (h *LedgerProjectionHandler) Reset( ctx context.Context, tx *sql.Tx, _ dogma.ProjectionResetScope, ) error
Reset clears all projection data.