I use Anorm to do database queries. When I do an executeUpdate()
, how should I do proper error handling? it has return type MayErr[IntegrityConstraintViolation,Int]
, is this a Set or a Map?
There is an example, but I don't 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 do I check if the query failed? (using result
), and how do I get the numer of affected rows if the query was successful?
At the moment I use 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 don't know how my error-handling code should look like. Is there any example on how to use the return value of type MayErr[IntegrityConstraintViolation,Int]
?