engine

package
v1.1.0-rc06 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2024 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseTableName

func ParseTableName(sql string) string

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 NewChain

func NewChain(middlewares ...Middleware) *Chain

NewChain 创建 middleware Chain

func (*Chain) After

func (c *Chain) After(ctx context.Context, ec *ExecutorContext, er *ExecutorResult)

After 执行后

func (*Chain) Before

func (c *Chain) Before(ctx context.Context, ec *ExecutorContext) error

Before 执行前

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 Executor

type Executor interface {
	Execer
	Queryer
}

Executor sql 语句执行器。Execer 和 Queryer 的组合

type ExecutorContext

type ExecutorContext struct {
	Type      SQLType
	TableName string
	SQL       string
	Args      []any
	NameArgs  any
	Start     time.Time
}

ExecutorContext SQL 执行器上下文

func ExecutorCtx

func ExecutorCtx(ctx context.Context) *ExecutorContext

ExecutorCtx 获取执行上下文

type ExecutorResult

type ExecutorResult struct {
	Err       error         // 执行异常异常
	Affected  int64         // 新增、删除、修改返回的影响行数
	QueryRows int64         // 查询记录行数
	Duration  time.Duration // 耗时
}

ExecutorResult 执行结果

type LogMiddleware

type LogMiddleware struct {
	Print Print
}

LogMiddleware 打印日志中间件

func NewLogMiddleware

func NewLogMiddleware(p Print) *LogMiddleware

NewLogMiddleware 创建打印日志中间件

func (LogMiddleware) After

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 查询语句执行器

type SQLType

type SQLType string

SQLType sql 类型

const (
	// SELECT 查询语句
	SELECT SQLType = "SELECT"
	// DELETE 删除语句
	DELETE SQLType = "DELETE"
	// UPDATE 更新语句
	UPDATE SQLType = "UPDATE"
	// INSERT 插入语句
	INSERT SQLType = "INSERT"
	// UNKNOWN 未知语句
	UNKNOWN SQLType = "UNKNOWN"
)

func ParseSQLType

func ParseSQLType(query string) SQLType

ParseSQLType 解析 sql 类型

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL