-
Notifications
You must be signed in to change notification settings - Fork 220
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
[ADP-2565] Make runSqlM
atomic
#4702
Conversation
aa37624
to
16257bc
Compare
ac8d761
to
b46a69e
Compare
b46a69e
to
307d0cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
testExceptions :: IO () | ||
testExceptions = do | ||
Sql.withConnection ":memory:" $ \conn -> do | ||
_ <- Sql.runSqlM action conn | ||
putStrLn "Before" | ||
printTablePerson conn | ||
Sql.runSqlM | ||
( do | ||
Sql.deleteWhere (colBirthYear Sql.>. 1800) tablePerson | ||
error "oops" | ||
) conn `catch` (\(_ :: SomeException) -> pure ()) | ||
putStrLn "After" | ||
printTablePerson conn | ||
where | ||
printTablePerson conn = | ||
mapM_ print =<< Sql.runSqlM (Sql.selectAll tablePerson) conn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider writing these demos as simple unit tests from the beginning?
I imagine it would be little additional work to e.g. replace printTablePerson conn
with
selectTablePerson conn
`shouldReturn`
[ ("Babbage",1791)
, ("William",1805)
, ("Ada",1815)
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider writing these demos as simple unit tests from the beginning?
Since I didn't know what the interface will look like, it didn't make sense for me to write the demo as a unit test in the beginning. But I agree that it makes much more sense now, and that's what I intend to do — in a future pull request. 😅
This pull request changes the semantics of
runSqlM
to becomeThis makes the
SqlM
monad less error-prone and more convenient to use, but disallows some performance techniques, such as SQL savepoints or concurrent access to the SQLite database. However, we need to wrap the monad in a less error-prone interface anyway, and we can always attempt to reintroduce these techniques later, so the gain in convenience is worth the trade now.This pull request also exposes the exception effect in the
SqlM
monad explicitly by exposing standard functions such asthrow
andcatch
.Comments
Demo.Database
provides a basic functionality check.Issue Number
ADP-2565