-
Notifications
You must be signed in to change notification settings - Fork 349
/
applicativeerror.scala
29 lines (24 loc) · 1.27 KB
/
applicativeerror.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT
package doobie.syntax
import cats.ApplicativeError
import doobie.util.{ catchsql => C }
import doobie.enumerated.SqlState
import java.sql.SQLException
class ApplicativeErrorOps[M[_], A](self: M[A])(implicit ev: ApplicativeError[M, Throwable]) {
def attemptSql: M[Either[SQLException, A]] = C.attemptSql(self)
def attemptSqlState: M[Either[SqlState, A]] = C.attemptSqlState(self)
def attemptSomeSqlState[B](f: PartialFunction[SqlState, B]): M[Either[B, A]] = C.attemptSomeSqlState(self)(f)
def exceptSql(handler: SQLException => M[A]): M[A] = C.exceptSql(self)(handler)
def exceptSqlState(handler: SqlState => M[A]): M[A] = C.exceptSqlState(self)(handler)
def exceptSomeSqlState(pf: PartialFunction[SqlState, M[A]]): M[A] = C.exceptSomeSqlState(self)(pf)
def onSqlException[B](action: M[B]): M[A] = C.onSqlException(self)(action)
}
trait ToApplicativeErrorOps {
implicit def toDoobieApplicativeErrorOps[M[_], A](ma: M[A])(
implicit ev: ApplicativeError[M, Throwable]
): ApplicativeErrorOps[M, A] =
new ApplicativeErrorOps(ma)
}
object applicativeerror extends ToApplicativeErrorOps