github.com/RevenueMonster/sqlike@v1.0.6/sqlike/options/transaction.go (about)

     1  package options
     2  
     3  import (
     4  	"database/sql"
     5  	"time"
     6  )
     7  
     8  // IsolationLevel :
     9  type IsolationLevel = sql.IsolationLevel
    10  
    11  // Various isolation levels that drivers may support in BeginTx.
    12  // If a driver does not support a given isolation level an error may be returned.
    13  //
    14  // See https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.
    15  const (
    16  	LevelDefault         = sql.LevelDefault
    17  	LevelReadUncommitted = sql.LevelReadUncommitted
    18  	LevelReadCommitted   = sql.LevelReadCommitted
    19  	LevelWriteCommitted  = sql.LevelWriteCommitted
    20  	LevelRepeatableRead  = sql.LevelRepeatableRead
    21  	LevelSnapshot        = sql.LevelSnapshot
    22  	LevelSerializable    = sql.LevelSerializable
    23  	LevelLinearizable    = sql.LevelLinearizable
    24  )
    25  
    26  // Transaction :
    27  func Transaction() *TransactionOptions {
    28  	return &TransactionOptions{}
    29  }
    30  
    31  // TransactionOptions :
    32  type TransactionOptions struct {
    33  	Duration       time.Duration
    34  	IsolationLevel IsolationLevel
    35  	ReadOnly       bool
    36  }
    37  
    38  // SetTimeOut :
    39  func (opts *TransactionOptions) SetTimeOut(duration time.Duration) *TransactionOptions {
    40  	opts.Duration = duration
    41  	return opts
    42  }
    43  
    44  // SetIsolationLevel :
    45  func (opts *TransactionOptions) SetIsolationLevel(level IsolationLevel) *TransactionOptions {
    46  	opts.IsolationLevel = level
    47  	return opts
    48  }
    49  
    50  // SetReadOnly :
    51  func (opts *TransactionOptions) SetReadOnly(readOnly bool) *TransactionOptions {
    52  	opts.ReadOnly = readOnly
    53  	return opts
    54  }