sql

package
v0.0.0-...-41c389d Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	Stmt
	BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
	Close() error
	PingContext(ctx context.Context) error
}

Conn 是数据库连接接口, 对应 *sql.Conn.

type DB

type DB interface {
	Stmt
	BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
	Close() error
	Conn(ctx context.Context) (Conn, error)
	PingContext(ctx context.Context) error
}

DB 是数据库接口, 对应 *sql.DB.

func WrapDB

func WrapDB(db *sql.DB, opts ...Option) DB

WrapDB 包装 *sql.DB 返回 DB 接口.

type Option

type Option func(*options)

Option 表示一些可选的参数.

func WithOutStat

func WithOutStat() Option

WithOutStat 关闭监控

func WithStat

func WithStat(stat stat.Stat) Option

WithStat 设置自定义监控默认是 metrics.DBDefault

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout 设置超时时间.

func WithTracing

func WithTracing() Option

WithTracing 启用 tracing 功能, 默认开启 tracing 功能.

func WithoutTracing

func WithoutTracing() Option

WithoutTracing 禁用 tracing 功能, 默认开启 tracing 功能.

type Row

type Row interface {
	Scan(dest ...interface{}) error
}

Row 对应 *sql.Row.

type Rows

type Rows interface {
	Close() error
	Columns() ([]string, error)
	ColumnTypes() ([]*sql.ColumnType, error)
	Err() error
	Next() bool
	NextResultSet() bool
	Scan(dest ...interface{}) error
}

Rows 对应 *sql.Rows.

type Stmt

type Stmt interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) Row

	// WithTimeout 返回一个新的 Stmt, 这个新的 Stmt 的超时时间是 timeout.
	//
	// 请注意当前的 Stmt 的不受影响.
	WithTimeout(timeout time.Duration) Stmt
}

Stmt 是数据库 Statement 接口, 可以通过这个接口操作数据库.

type Tx

type Tx interface {
	Stmt
	Commit() error
	Rollback() error
}

Tx 是数据库事务接口, 对应 *sql.Tx.

Jump to

Keyboard shortcuts

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