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 WithExecutorCtx ¶
func WithExecutorCtx(ctx context.Context, ec *ExecutorContext) context.Context
WithExecutorCtx 添加执行上下文
Types ¶
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 执行器上下文
type ExecutorResult ¶
type ExecutorResult struct {
Err error // 执行异常异常
Affected int64 // 新增、删除、修改返回的影响行数
QueryRows int64 // 查询记录行数
Duration time.Duration // 耗时
}
ExecutorResult 执行结果
type LogMiddleware ¶
type LogMiddleware struct {
Print Print
}
LogMiddleware 打印日志中间件
func (LogMiddleware) After ¶
func (l LogMiddleware) After(ctx context.Context, ec *ExecutorContext, er *ExecutorResult)
After 执行后
func (LogMiddleware) Before ¶
func (l LogMiddleware) Before(ctx context.Context, ec *ExecutorContext) error
Before 执行前
type Middleware ¶
type Middleware interface {
// Before sql 执行前
Before(ctx context.Context, ec *ExecutorContext) error
// After sql 执行后
After(ctx context.Context, ec *ExecutorContext, er *ExecutorResult)
}
Middleware sql 执行中间件
type Print ¶
type Print func(ctx context.Context, ec *ExecutorContext, er *ExecutorResult)
Print 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
}
Queryer 查询语句执行器
Click to show internal directories.
Click to hide internal directories.