github.com/wangyougui/gf/v2@v2.6.5/database/gdb/gdb_core_link.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package gdb
     8  
     9  import (
    10  	"database/sql"
    11  )
    12  
    13  // dbLink is used to implement interface Link for DB.
    14  type dbLink struct {
    15  	*sql.DB         // Underlying DB object.
    16  	isOnMaster bool // isOnMaster marks whether current link is operated on master node.
    17  }
    18  
    19  // txLink is used to implement interface Link for TX.
    20  type txLink struct {
    21  	*sql.Tx
    22  }
    23  
    24  // IsTransaction returns if current Link is a transaction.
    25  func (l *dbLink) IsTransaction() bool {
    26  	return false
    27  }
    28  
    29  // IsOnMaster checks and returns whether current link is operated on master node.
    30  func (l *dbLink) IsOnMaster() bool {
    31  	return l.isOnMaster
    32  }
    33  
    34  // IsTransaction returns if current Link is a transaction.
    35  func (l *txLink) IsTransaction() bool {
    36  	return true
    37  }
    38  
    39  // IsOnMaster checks and returns whether current link is operated on master node.
    40  // Note that, transaction operation is always operated on master node.
    41  func (l *txLink) IsOnMaster() bool {
    42  	return true
    43  }