Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseTableName ¶
ParseTableName extracts the table name from a single table SQL query.
func SetExecutorContext ¶
func SetExecutorContext(ctx context.Context, ec *ExecutorContext) context.Context
SetExecutorContext 添加执行上下文
Types ¶
type AfterHandler ¶
type AfterHandler func(ctx context.Context, ec *ExecutorContext, er *ExecutorResult)
AfterHandler sql 执行后回调
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain 中间件执行链
func (*Chain) After ¶
func (c *Chain) After(ctx context.Context, ec *ExecutorContext, er *ExecutorResult)
After 执行后
type Execer ¶
type Execer interface {
// NamedExecContext 使用命名参数执行sql
NamedExecContext(ctx context.Context, execSQL string, arg any) (sql.Result, error)
// ExecContext 使用数组参数执行sql
ExecContext(ctx context.Context, execSQL string, args ...any) (sql.Result, error)
}
Execer 更新语句执行器
type ExecutorContext ¶
type ExecutorContext struct {
Type SQLType
TableName string
SQL string
Args []any
NameArgs any
Start time.Time
}
ExecutorContext SQL 执行器上下文
func GetExecutorContext ¶
func GetExecutorContext(ctx context.Context) *ExecutorContext
GetExecutorContext 获取执行上下文
type ExecutorResult ¶
type ExecutorResult struct {
Err error // 执行异常异常
Affected int64 // 新增、删除、修改返回的影响行数
QueryRows int64 // 查询记录行数
Duration time.Duration // 耗时
}
ExecutorResult 执行结果
type Hook ¶
type Hook interface {
// Before sql 执行前
Before(ctx context.Context, ec *ExecutorContext) error
// After sql 执行后
After(ctx context.Context, ec *ExecutorContext, er *ExecutorResult)
}
Hook sql 执行中间件
type Queryer ¶
type Queryer interface {
// SelectContext 查询多条数据
SelectContext(ctx context.Context, dest any, query string, args ...any) error
// GetContext 查询单条数据
GetContext(ctx context.Context, dest any, query string, args ...any) error
// QueryContext 查询多条数据,返回 sql.Rows
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
Queryer 查询语句执行器
Click to show internal directories.
Click to hide internal directories.