#127 feat: repository wrapper invoking the generated hooks - #267
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #127
The orphan rule keeps a user crate from implementing
{Entity}Hooksforsqlx::PgPool— both the trait and the type are foreign there — so the repository impl on the pool could never call hooks, and the documented answer was to call them by hand at the service layer.#[entity(hooks)]now also emits{Entity}Repo<H>, the type that owns both:create,savebefore_createmay rewrite the DTO,after_createsees the persisted rowupdatebefore_updatemay rewrite the patchdeleteafter_deleteonly when a row was actually affectedhard_delete,restoreDeref, unchangedA failing
before_*aborts before anything is written. The hook error only has to convert into the repository error, so hooks keep their own error type — this is the RFC's option A, with the delegation done throughDerefso the wrapper answers every repository method instead of re-declaring them.Backward compatible: the bare pool path is untouched, and manual wiring keeps working.
Four live-Postgres cases cover the order of calls across create, update, delete and restore; that a refusing
before_createleaves the table empty and never runs the after hook; that a refusingbefore_deleteleaves the row in place; and that a read invokes nothing.examples/hooksis rewritten around the wrapper — the handlers no longer call hooks by hand. README, the module docs and the hooks page in all five wiki languages are updated.