multi-model

command
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Example: multi-model

Demonstrates multi-table transactions, domain events, and transaction hooks using DDD style (unexported fields + domain methods). This is the only example that uses this encapsulation pattern — all other examples use exported fields.

Key concepts shown:

  • Domain model with Transfer method that modifies two entities atomically
  • RecordEvent captures domain events during business logic
  • OnBeforeCommit hook writes events to an audit_log table within the same transaction (rolled back if commit fails)
  • OnAfterCommit hook fires only after successful commit (e.g. logging)

Usage:

cd examples/multi-model
go run ../../cmd/drel generate   # generates users/user_drel.go + db/drel_gen.go
export DATABASE_URL="postgres://localhost:5432/drelexample?sslmode=disable"
go run .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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