I use Anorm to execute database queries. When I do executeUpdate(), how should I do the correct error handling? Does it have a return type MayErr[IntegrityConstraintViolation,Int], is it a set or a card?
There is an example , but I do not understand how I should handle the return value:
val result = SQL("delete from City where id = 99").executeUpdate().fold(
e => "Oops, there was an error" ,
c => c + " rows were updated!"
)
How to check if the request failed? (using result), and how can I get the number of rows affected if the request was successful?
I am currently using this code:
SQL(
"""
INSERT INTO users (firstname, lastname) VALUES ({firstname}, {lastname})
"""
).on("firstname" -> user.firstName, "lastname" -> user.lastName)
.executeUpdate().fold(
e => "Oops, therw was an error",
c => c + " rows were updated!"
)
But I do not know what the error handling code should look like. Is there any example of how to use the return value of a type MayErr[IntegrityConstraintViolation,Int]?