projections

package
v0.0.0-...-c4decb3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSchema

func CreateSchema(ctx context.Context, db *sql.DB) error

CreateSchema creates the schema elements required by the projection handlers.

func MustNewDB

func MustNewDB() *sql.DB

MustNewDB returns an in-memory SQLite database, with database tables necessary to run the example application.

It panics if the database is unable to be opened, or the schema is unable to be created.

func NewDB

func NewDB() (*sql.DB, error)

NewDB returns an in-memory SQLite database, with database tables necessary to run the example application.

It returns an error if the database is unable to be opened, or the schema is unable to be created.

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

Configure configs the engine for this projection.

func (*CustomerProjectionHandler) HandleEvent

HandleEvent inserts into the "customers" table whenever the bank acquires a new customer.

func (*CustomerProjectionHandler) Reset

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

Configure configs the engine for this projection.

func (*LedgerProjectionHandler) HandleEvent

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

Reset clears all projection data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL