db

package module
v0.0.0-...-bd2440c Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TypeToContextKey = &contextKey{"TypeTo"}
	DataToContextKey = &contextKey{"DataTo"}
)

Functions

func ColumnArray

func ColumnArray(m []map[string]interface{}, key string) []interface{}

以数组形式返回key列的值

m []map[string]interface{}	数据库的数据
key string					key键名
[]interface{}				返回key对应的值,不包含nil值

func ColumnArrayNil

func ColumnArrayNil(m []map[string]interface{}, key string) []interface{}

以数组形式返回key列的值

m []map[string]interface{}	数据库的数据
key string					key键名
[]interface{}				返回key对应的值,包含nil值

func ColumnFilter

func ColumnFilter(m []map[string]interface{}, f func(string) bool) []map[string]interface{}

过滤指定例

m []map[string]interface{}	数据库的数据
f func(string) bool			返回true,过滤该例
[]map[string]interface{}	过滤后的数据

Types

type DB

type DB struct {
	*sql.DB
	Timeout          time.Duration
	FormatColumnName bool // 将例名 AbcDf	=> abcDf
	TypeTo           func(*sql.ColumnType) reflect.Type
	DataTo           func(string, interface{}) interface{}
	ErrorLog         *log.Logger
	DebugPrint       bool
	DebugResult      func(tx *sql.Tx, ctx context.Context, sqlstr string, args ...interface{}) interface{}
	// contains filtered or unexported fields
}

说明:https://github.com/lib/pq/blob/master/doc.go postgresql://[user[:password]@][netloc][:port][,...][/dbname][?param1=value1&...]

func (*DB) Close

func (T *DB) Close() error

func (*DB) Exec

func (T *DB) Exec(tx *sql.Tx, sqlstr string, args ...interface{}) (result sql.Result, err error)

支持写入

func (*DB) ExecContext

func (T *DB) ExecContext(ctx context.Context, tx *sql.Tx, sqlstr string, args ...interface{}) (result sql.Result, err error)

func (*DB) Has

func (T *DB) Has(sqlstr string, args ...interface{}) error

判断数据存在,支持返回错误:error, nil, ErrNoRows

func (*DB) HasContext

func (T *DB) HasContext(ctx context.Context, sqlstr string, args ...interface{}) error

func (*DB) Logf

func (T *DB) Logf(format string, a ...interface{})

日志

func (*DB) Open

func (T *DB) Open(driverName, dataSourceName string) (*DB, error)

func (*DB) Query

func (T *DB) Query(tx *sql.Tx, sqlstr string, args ...interface{}) (data []map[string]interface{}, err error)

支持读取/写入,支持返回错误:error, nil, ErrNoRows

func (*DB) QueryContext

func (T *DB) QueryContext(ctx context.Context, tx *sql.Tx, sqlstr string, args ...interface{}) (data []map[string]interface{}, err error)

func (*DB) QueryRow

func (T *DB) QueryRow(tx *sql.Tx, sqlstr string, args ...interface{}) Rower

支持读取/写入,支持返回错误:error, nil, ErrNoRows

func (*DB) QueryRowContext

func (T *DB) QueryRowContext(ctx context.Context, tx *sql.Tx, sqlstr string, args ...interface{}) Rower

func (*DB) TxBegin

func (T *DB) TxBegin() (tx *sql.Tx, commit func(*error), err error)

func (*DB) TxCommit

func (T *DB) TxCommit(tx *sql.Tx, e *error)

type Rower

type Rower interface {
	Scan(dest ...interface{}) error
	Err() error
}

Jump to

Keyboard shortcuts

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