1 Star 0 Fork 0

Erdian718/sqlx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tx_builder.go 932 Bytes
一键复制 编辑 原始数据 按行查看 历史
Erdian718 提交于 2025-02-20 13:11 +08:00 . Support linq APIs
package sqlx
import (
"context"
"database/sql"
)
// TxBuilder represents a transaction builder.
type TxBuilder struct {
db *DB
ctx context.Context
readonly bool
isolation IsolationLevel
}
// Context sets the context.
// Default is Background.
func (tb *TxBuilder) Context(ctx context.Context) *TxBuilder {
tb.ctx = ctx
return tb
}
// ReadOnly sets the transaction readonly or not.
// Default is false.
func (tb *TxBuilder) ReadOnly(readonly bool) *TxBuilder {
tb.readonly = readonly
return tb
}
// Isolation sets the isolation level.
// Default is LevelDefault.
func (tb *TxBuilder) Isolation(isolation IsolationLevel) *TxBuilder {
tb.isolation = isolation
return tb
}
// Build builds the transaction.
func (tb *TxBuilder) Build() (*Tx, error) {
raw, err := tb.db.raw.BeginTx(tb.ctx, &sql.TxOptions{
Isolation: tb.isolation,
ReadOnly: tb.readonly,
})
return &Tx{raw: raw, ctx: tb.ctx}, err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/erdian718/sqlx.git
git@gitee.com:erdian718/sqlx.git
erdian718
sqlx
sqlx
main

搜索帮助