forked from typelevel/doobie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transactionisolation.scala
63 lines (48 loc) · 2.29 KB
/
transactionisolation.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 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.enumerated
import cats.ApplicativeError
import cats.Show
import cats.kernel.Eq
import cats.kernel.instances.int.*
import doobie.util.invariant.*
import java.sql.Connection.*
/** @group Types */
sealed abstract class TransactionIsolation(val toInt: Int) extends Product with Serializable
/** @group Modules */
object TransactionIsolation {
/** @group Values */
case object TransactionNone extends TransactionIsolation(TRANSACTION_NONE)
/** @group Values */
case object TransactionReadUncommitted extends TransactionIsolation(TRANSACTION_READ_UNCOMMITTED)
/** @group Values */
case object TransactionReadCommitted extends TransactionIsolation(TRANSACTION_READ_COMMITTED)
/** @group Values */
case object TransactionRepeatableRead extends TransactionIsolation(TRANSACTION_REPEATABLE_READ)
/** @group Values */
case object TransactionSerializable extends TransactionIsolation(TRANSACTION_SERIALIZABLE)
def fromInt(n: Int): Option[TransactionIsolation] =
Some(n) collect {
case TransactionNone.toInt => TransactionNone
case TransactionReadUncommitted.toInt => TransactionReadUncommitted
case TransactionReadCommitted.toInt => TransactionReadCommitted
case TransactionRepeatableRead.toInt => TransactionRepeatableRead
case TransactionSerializable.toInt => TransactionSerializable
}
def fromIntF[F[_]](n: Int)(implicit AE: ApplicativeError[F, Throwable]): F[TransactionIsolation] =
ApplicativeError.liftFromOption(fromInt(n), InvalidOrdinal[TransactionIsolation](n))
implicit val EqTransactionIsolation: Eq[TransactionIsolation] =
Eq.by(_.toInt)
implicit val TransactionIsolationShow: Show[TransactionIsolation] = {
case TransactionIsolation.TransactionNone => "TRANSACTION_NONE"
case TransactionIsolation.TransactionReadUncommitted =>
"TRANSACTION_READ_UNCOMMITTED"
case TransactionIsolation.TransactionReadCommitted =>
"TRANSACTION_READ_COMMITTED"
case TransactionIsolation.TransactionRepeatableRead =>
"TRANSACTION_REPEATABLE_READ"
case TransactionIsolation.TransactionSerializable =>
"TRANSACTION_SERIALIZABLE"
}
}