Use when creating ROM Repositories in Hanami 2.x, including CRUD operations, defining custom queries, configuring associations, setting up aggregate roots, entity mapping, transaction handling, and implementing the Repository as your domain persistence layer. Relevant for database access, rom-rb relations, sequel adapter setup, and wiring repositories into actions via dependency injection.
Installation
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Use when creating ROM Repositories in Hanami 2.x, including CRUD operations, defining custom queries, configuring associations, setting up aggregate roots, entity mapping, transaction handling, and implementing the Repository as your domain persistence layer. Relevant for database access, rom-rb relations, sequel adapter setup, and wiring repositories into actions via dependency injection.
Verify container registration:
After creating the repository, confirm it is correctly registered in the Hanami container before wiring it into actions. Run in the console:
Add domain methods:
Write specific read and write methods to isolate your actions from raw relation access:
defactive
users.active.to_a
enddeffind_by_email(email)
users.by_email(email).one
end
Advanced Topics
Use transactions for multi-step writes:
Wrap mutations in transaction blocks. If the block raises an error, the transaction is automatically rolled back and the error is re-raised.
transaction do
accounts.update(from_id, balance: from_account.balance - amount)
accounts.update(to_id, balance: to_account.balance + amount)
end
Map to custom Entities:
Configure the struct_namespace to automatically map SQL relation rows to custom Entity domain models.
Do not expose Relations directly:
Actions must fetch and modify data via Repositories. Bypassing repositories to query relations directly in actions/views is an anti-pattern.
For detailed repository pattern examples, see REPOSITORIES.md.
Integration
Related Skill
When to chain
define-relation
define-relation — Relations map table schemas before repositories query them.
define-entity
define-entity — Represents the struct objects returned by the repository.
create-action
Actions inject repositories to read/write data.
write-rom-spec
Test repository methods inside in-memory ROM database specs.