db

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAll added in v0.25.0

func FindAll[R Finder](db *sql.DB, initial R) (r []R, err error)

FindAll sql里select的字段数量必须与R的ScanFields方法返回的数组元素数量一致

func FindOne added in v0.25.0

func FindOne[R Finder](db *sql.DB, ir R) (r R, err error)

func PrintFields added in v0.25.0

func PrintFields(fields []any)

func WrapSQLConn

func WrapSQLConn(
	ctx context.Context,
	db *sql.DB,
	f func(
		ctx context.Context,
		conn *sql.Conn,
	) error,
) error

func WrapSQLQueryRows

func WrapSQLQueryRows(
	ctx context.Context,
	db *sql.DB,
	stmt string,
	args []interface{},
	dest ...interface{},
) error

WrapSQLQueryRows query by stmt and args, return values with dest

Types

type Finder added in v0.25.0

type Finder interface {
	Query() (query string, args []any) // 返回查询语句,参数

	// 新建同类型对象,不要使用同一个,用来接收结果
	// 	这里返回的结果必须是本类型对象,但这种写法其实不能保证(可以返回其它实现了本接口的对象),使用时注意
	// fields指定对象字段与列的对应关系
	NewScanObjAndFields(colTypes []*sql.ColumnType) (finder Finder, fields []any)
}

Jump to

Keyboard shortcuts

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