]> Cypherpunks repositories - gostls13.git/commitdiff
database/sql: add String method to IsolationLevel
authorAlexey Palazhchenko <alexey.palazhchenko@gmail.com>
Tue, 6 Feb 2018 05:56:53 +0000 (08:56 +0300)
committerDaniel Theophanes <kardianos@gmail.com>
Thu, 22 Feb 2018 15:17:52 +0000 (15:17 +0000)
Fixes #23632

Change-Id: I7197e13df6cf28400a6dd86c110f41129550abb6
Reviewed-on: https://go-review.googlesource.com/92235
Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
src/database/sql/sql.go

index 5956d6ad46d7d553dc0cc02a272fda236831d8b1..24e906938eb83d096e38235770e2634267b3a5f7 100644 (file)
@@ -24,6 +24,7 @@ import (
        "reflect"
        "runtime"
        "sort"
+       "strconv"
        "sync"
        "sync/atomic"
        "time"
@@ -132,6 +133,31 @@ const (
        LevelLinearizable
 )
 
+func (i IsolationLevel) String() string {
+       switch i {
+       case LevelDefault:
+               return "Default"
+       case LevelReadUncommitted:
+               return "Read Uncommitted"
+       case LevelReadCommitted:
+               return "Read Committed"
+       case LevelWriteCommitted:
+               return "Write Committed"
+       case LevelRepeatableRead:
+               return "Repeatable Read"
+       case LevelSnapshot:
+               return "Snapshot"
+       case LevelSerializable:
+               return "Serializable"
+       case LevelLinearizable:
+               return "Linearizable"
+       default:
+               return "IsolationLevel(" + strconv.Itoa(int(i)) + ")"
+       }
+}
+
+var _ fmt.Stringer = LevelDefault
+
 // TxOptions holds the transaction options to be used in DB.BeginTx.
 type TxOptions struct {
        // Isolation is the transaction isolation level.