1 Star 1 Fork 1

c./goframe框架

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gdb_core_ctx.go 3.27 KB
一键复制 编辑 原始数据 按行查看 历史
// 版权归GoFrame作者(https://goframe.org)所有。保留所有权利。
//
// 本源代码形式受MIT许可证条款约束。
// 如果未随本文件一同分发MIT许可证副本,
// 您可以在https://github.com/gogf/gf处获取。
// md5:a9832f33b234e3f3
package db类
import (
"context"
"sync"
gcode "gitee.com/go_888/goframe/errors/gcode"
gerror "gitee.com/go_888/goframe/errors/gerror"
gctx "gitee.com/go_888/goframe/os/gctx"
)
// internalCtxData 为内部使用目的,在 ctx 中存储数据。 md5:95073898cc1f4772
type internalCtxData struct {
sync.Mutex
// 当前操作中使用的配置节点。 md5:85f106587581bb38
ConfigNode *X结构_配置
}
// column 用于内部目的,在ctx中存储列数据。 md5:12a8a80132bf8ae7
type internalColumnData struct {
// 来自数据库服务器的响应结果中的第一列。
// 此属性用于值/计数选择语句的目的,以避免可能修改结果列的HOOK处理器,这可能会混淆值/计数选择语句的逻辑。
// md5:c678f20e25487136
FirstResultColumn string
}
const (
internalCtxDataKeyInCtx gctx.X类型_StrKey = "InternalCtxData"
internalColumnDataKeyInCtx gctx.X类型_StrKey = "InternalColumnData"
// `ignoreResultKeyInCtx` 是为了一些不支持 `RowsAffected` 函数的数据库驱动(例如:`clickhouse`)设置的标记。`clickhouse` 不支持获取插入/更新的结果,但在执行 `RowsAffected` 时会返回错误。在这里,我们忽略对 `RowsAffected` 的调用,以避免触发错误,而不是在错误发生后忽略它们。
// md5:4a7864c37326a119
ignoreResultKeyInCtx gctx.X类型_StrKey = "IgnoreResult"
)
func (c *X结构_Core) injectInternalCtxData(ctx context.Context) context.Context {
// 如果内部数据已经被注入,则不做任何操作。 md5:ae258e1c66cb106a
if ctx.Value(internalCtxDataKeyInCtx) != nil {
return ctx
}
return context.WithValue(ctx, internalCtxDataKeyInCtx, &internalCtxData{
ConfigNode: c.config,
})
}
func (c *X结构_Core) setConfigNodeToCtx(ctx context.Context, node *X结构_配置) error {
value := ctx.Value(internalCtxDataKeyInCtx)
if value == nil {
return gerror.X创建错误码(gcode.X变量_CodeInternalError, `上下文中未找到内部数据`)
}
data := value.(*internalCtxData)
data.Lock()
defer data.Unlock()
data.ConfigNode = node
return nil
}
func (c *X结构_Core) getConfigNodeFromCtx(ctx context.Context) *X结构_配置 {
if value := ctx.Value(internalCtxDataKeyInCtx); value != nil {
data := value.(*internalCtxData)
data.Lock()
defer data.Unlock()
return data.ConfigNode
}
return nil
}
func (c *X结构_Core) injectInternalColumn(ctx context.Context) context.Context {
return context.WithValue(ctx, internalColumnDataKeyInCtx, &internalColumnData{})
}
func (c *X结构_Core) getInternalColumnFromCtx(ctx context.Context) *internalColumnData {
if v := ctx.Value(internalColumnDataKeyInCtx); v != nil {
return v.(*internalColumnData)
}
return nil
}
func (c *X结构_Core) X底层_InjectIgnoreResult(ctx context.Context) context.Context {
if ctx.Value(ignoreResultKeyInCtx) != nil {
return ctx
}
return context.WithValue(ctx, ignoreResultKeyInCtx, true)
}
func (c *X结构_Core) X底层_GetIgnoreResultFromCtx(ctx context.Context) bool {
return ctx.Value(ignoreResultKeyInCtx) != nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/go_888/goframe.git
git@gitee.com:go_888/goframe.git
go_888
goframe
goframe框架
782a3f7170cf

搜索帮助