sqlutil

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDataSourceString

func BuildDataSourceString(opts Options) string

构建连接字符串

func DeleteMany

func DeleteMany(tx AbstractDBBase, query string, args ...interface{}) (rowsAffected int64, success bool)

删除多条数据

func DeleteOne

func DeleteOne(tx AbstractDBBase, query string, args ...interface{}) (rowsAffected int64, success bool)

删除一条数据

func DisableDebug

func DisableDebug()

func EnableDebug

func EnableDebug()

func FindCount

func FindCount(tx AbstractDBBase, query string, args ...interface{}) (count int64, success bool)

查询记录数量,需要 SELECT count(*) AS count FROM ... 这样的格式

func FindMany

func FindMany(tx AbstractDBBase, dest interface{}, query string, args ...interface{}) (success bool)

查询多条数据

func FindOne

func FindOne(tx AbstractDBBase, dest interface{}, query string, args ...interface{}) (success bool)

查询一条数据

func InsertMany

func InsertMany(tx AbstractDBBase, query string, args ...interface{}) (lastInsertId int64, success bool)

插入多条记录

func InsertOne

func InsertOne(tx AbstractDBBase, query string, args ...interface{}) (insertId int64, success bool)

插入一条数据

func MustOpen

func MustOpen(driverName string, dataSourceName string) *sqlx.DB

创建数据库连接,如果失败则panic

func MustOpenWithOptions

func MustOpenWithOptions(driverName string, opts Options) *sqlx.DB

创建数据库连接,如果失败则panic

func Open

func Open(driverName string, dataSourceName string) (*sqlx.DB, error)

创建数据库连接

func OpenWithOptions

func OpenWithOptions(driverName string, opts Options) (*sqlx.DB, error)

创建数据库连接

func UpdateMany

func UpdateMany(tx AbstractDBBase, query string, args ...interface{}) (rowsAffected int64, success bool)

更新多条数据

func UpdateOne

func UpdateOne(tx AbstractDBBase, query string, args ...interface{}) (rowsAffected int64, success bool)

更新一条数据

Types

type AbstractDB

type AbstractDB interface {
	AbstractDBBase
	MustBegin() AbstractTx
}

type AbstractDBBase

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

type AbstractTx

type AbstractTx interface {
	AbstractDBBase
	Rollback() error
	Commit() error
}

type DB

type DB = sqlx.DB

type Options

type Options struct {
	Host       string
	Port       int
	User       string
	Password   string
	Database   string
	Charset    string
	Timezone   string // +8:00
	ParseTime  bool
	AutoCommit bool
	Params     map[string]string
}

type QueryCountRow

type QueryCountRow struct {
	Count int64 `db:"count"`
}

type Row

type Row = map[string]interface{}

type Tx

type Tx = sqlx.Tx

Jump to

Keyboard shortcuts

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