gf/database/gdb/gdb_core_link.go

44 lines
1.1 KiB
Go
Raw Normal View History

2021-05-21 15:30:21 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gdb
import (
"database/sql"
)
// dbLink is used to implement interface Link for DB.
type dbLink struct {
2022-03-21 21:17:48 +08:00
*sql.DB // Underlying DB object.
isOnMaster bool // isOnMaster marks whether current link is operated on master node.
2021-05-21 15:30:21 +08:00
}
// txLink is used to implement interface Link for TX.
type txLink struct {
*sql.Tx
}
// IsTransaction returns if current Link is a transaction.
2022-03-21 21:17:48 +08:00
func (l *dbLink) IsTransaction() bool {
2021-05-21 15:30:21 +08:00
return false
}
2022-03-21 21:17:48 +08:00
// IsOnMaster checks and returns whether current link is operated on master node.
func (l *dbLink) IsOnMaster() bool {
return l.isOnMaster
}
2021-05-21 15:30:21 +08:00
// IsTransaction returns if current Link is a transaction.
2022-03-21 21:17:48 +08:00
func (l *txLink) IsTransaction() bool {
return true
}
// IsOnMaster checks and returns whether current link is operated on master node.
// Note that, transaction operation is always operated on master node.
func (l *txLink) IsOnMaster() bool {
2021-05-21 15:30:21 +08:00
return true
}