我使用Anorm进行数据库查询。当我做一个executeUpdate()
,我应该如何做正确的错误处理?它有返回类型MayErr[IntegrityConstraintViolation,Int]
,这是 Set 还是 Map?
有一个例子,但我不明白我应该如何处理返回值:
val result = SQL("delete from City where id = 99").executeUpdate().fold(
e => "Oops, there was an error" ,
c => c + " rows were updated!"
)
如何检查查询是否失败?(使用result
),如果查询成功,我如何获得受影响的行数?
目前我使用这段代码:
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!"
)
但我不知道我的错误处理代码应该是什么样子。有没有关于如何使用 type 的返回值的例子MayErr[IntegrityConstraintViolation,Int]
?