mdb

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GoTypeString  = 1
	GoTypeInt64   = 2
	GoTypeBytes   = 3
	GoTypeFloat64 = 4
	GoTypeTime    = 5
)

数据库数据类型

Variables

View Source
var TypeMySQLToGoMap = map[string]int64{
	"BIT":        1,
	"TEXT":       1,
	"BLOB":       3,
	"DATETIME":   5,
	"DOUBLE":     4,
	"ENUM":       1,
	"FLOAT":      4,
	"GEOMETRY":   1,
	"MEDIUMINT":  2,
	"JSON":       1,
	"INT":        2,
	"LONGTEXT":   1,
	"LONGBLOB":   3,
	"BIGINT":     2,
	"MEDIUMTEXT": 1,
	"MEDIUMBLOB": 3,
	"DATE":       5,
	"DECIMAL":    1,
	"SET":        1,
	"SMALLINT":   2,
	"BINARY":     3,
	"CHAR":       1,
	"TIME":       5,
	"TIMESTAMP":  5,
	"TINYINT":    2,
	"TINYTEXT":   1,
	"TINYBLOB":   3,
	"VARBINARY":  3,
	"VARCHAR":    1,
	"YEAR":       2,
}

TypeMySQLToGoMap 类型转换关系

Functions

func Create

func Create(dataSourceName string, showSQL bool) *sqlx.DB

Create 创建数据库链接

func ExecuteCountContent

func ExecuteCountContent(ctx context.Context, tx ExecuteAble, query string, argMap map[string]interface{}) (int64, error)

ExecuteCountContent 执行sql语句返回执行个数

func ExecuteLastIDContent

func ExecuteLastIDContent(ctx context.Context, tx ExecuteAble, query string, argMap map[string]interface{}) (int64, error)

ExecuteLastIDContent 执行sql语句并返回lastID

func GetContent

func GetContent(ctx context.Context, tx ExecuteAble, dest interface{}, query string, argMap map[string]interface{}) (bool, error)

GetContent 执行sql查询并返回当个元素

func RowsContent

func RowsContent(ctx context.Context, tx ExecuteAble, query string, argMap map[string]interface{}) ([]map[string]interface{}, error)

RowsContent 执行sql查询并返回多行

func SelectContent

func SelectContent(ctx context.Context, tx ExecuteAble, dest interface{}, query string, argMap map[string]interface{}) error

SelectContent 执行sql查询并返回多行

func SetShowSQL

func SetShowSQL(b bool)

SetShowSQL 设置是否显示sql

func Transaction

func Transaction(ctx context.Context, db *sqlx.DB, f func(dbTx ExecuteAble) error) error

Transaction 执行事物

Types

type ExecuteAble

type ExecuteAble interface {
	Rebind(string) string

	Get(dest interface{}, query string, args ...interface{}) error
	Exec(query string, args ...interface{}) (sql.Result, error)
	Select(dest interface{}, query string, args ...interface{}) error

	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
}

ExecuteAble 数据库接口

Jump to

Keyboard shortcuts

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