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 .
Click to show internal directories.
Click to hide internal directories.