client

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	OpExec  = 1
	OpQuery = 2
)

Variables

View Source
var ErrBreak = errors.New("sql scan rows break")

ErrBreak 如果 NextFunc 函数返回 ErrBreak 则提前结束 scan 循环

Functions

This section is empty.

Types

type Client

type Client interface {
	Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)   // 执行语句
	Query(ctx context.Context, next NextFunc, query string, args ...interface{}) error // 查询语句
	Prepare(ctx context.Context, query string) (*sql.Stmt, error)                      // 预绑定
	BeginTx(ctx context.Context) error                                                 // 开启事务
	FinishTx(err error) error                                                          // 结束事务
}

Client 底层查询代理

func NewClient

func NewClient(addr *util.DBAddress) (Client, error)

NewClient 新建一个 db client

type NextFunc

type NextFunc func(*sql.Rows) error

NextFunc query 请求时,每一行数据记录执行的逻辑, 包装在框架底层,可以防止用户漏写 rows.Close, rows.Err 等, 也可以防止 scan 过程中 context 被取消 返回值 error = nil 继续下一个 row, ErrBreak 则提前结束循环 !=nil 返回失败

type Options

type Options struct {
	MaxIdle     int           // 最大空闲连接数
	MaxOpen     int           // 最大活跃连接数
	MaxLifetime time.Duration // 最大连接生存时间
	MaxIdleTime time.Duration // 最大空闲时间
}

Jump to

Keyboard shortcuts

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