mdb

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: MIT Imports: 11 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 gin.H) (int64, error)

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

func ExecuteCountManyContent added in v0.0.7

func ExecuteCountManyContent(ctx context.Context, tx ExecuteAble, query string, n int, args ...interface{}) (int64, error)

ExecuteCountManyContent 返回sql语句并返回执行行数

func ExecuteLastIDContent

func ExecuteLastIDContent(ctx context.Context, tx ExecuteAble, query string, argMap gin.H) (int64, error)

ExecuteLastIDContent 执行sql语句并返回lastID

func GetContent

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

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

func RowsContent

func RowsContent(ctx context.Context, tx ExecuteAble, query string, argMap gin.H) ([]gin.H, error)

RowsContent 执行sql查询并返回多行

func SelectContent

func SelectContent(ctx context.Context, tx ExecuteAble, dest interface{}, query string, argMap gin.H) 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