-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to write a decoder that fails unless exactly one row was updated? #94
Comments
Can you please elaborate on your case? I'm struggling to understand why encoding this failure with logic and then handling the result in your session isn't sufficient. E.g., like this: someQuery :: Query SomeParams Bool
someQuery = Query.statement someSql someEncoder decoder True
where
decoder = fmap (== 1) Decoders.rowsAffected
someSession :: Session SomeSessionResult
someSession = do
valid <- Session.query someQueryParams someQuery
if valid
then continueAsIfItsValid
else handleFailure |
Hey, thanks for taking the time to consider this. Indeed, that works. I'm working on a codebase that has a datatype of I then have some insert queries that rely on UUIDs and uniqueness constraints to ensure no collisions. Even so, I'd like to check |
Those failure cases are sort of forced upon us by the Postgres side. It doesn't mean that we should extend in that direction.
Sanity check is in part what you're doing in your insertFoo :: Foo -> ExceptT ValidationError Transaction () |
I'm using an older arrowized version of hasql. How would you write a decoder that fails if
rowsAffected
does not yield1
? It does not seem to be possible because not enough stuff is exported for users to create their own exceptions.For now I am doing the check and throw outside of the transaction, and that works ok, but it is not how I'd prefer to decompose concerns.
The text was updated successfully, but these errors were encountered: