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.
설치
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
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.