sqlutil

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DELETE = "DELETE"
View Source
const INNER_JOIN = "INNER JOIN"
View Source
const INSERT = "INSERT"
View Source
const INSERT_OR_UPDATE_CONFLICT = "INSERT_OR_UPDATE_CONFLICT"
View Source
const INSERT_OR_UPDATE_DUPLICATE = "INSERT_OR_UPDATE_DUPLICATE"
View Source
const JOIN = "JOIN"
View Source
const LEFT_JOIN = "LEFT JOIN"
View Source
const RIGHT_JOIN = "RIGHT JOIN"
View Source
const SELECT = "SELECT"
View Source
const SELECT_DISTINCT = "SELECT DISTINCT"
View Source
const UPDATE = "UPDATE"

Variables

This section is empty.

Functions

func BatchExec added in v1.9.4

func BatchExec(db AbstractDB, sqlList ...string) error

事务执行多行SQL

func DisableDebug

func DisableDebug()

func EnableDebug

func EnableDebug()

func Exec

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

执行查询,无返回结果

func ExecInsert

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

执行插入记录查询,返回最后插入ID

func GetDefaultLocation

func GetDefaultLocation() *time.Location

func InterpolateParams

func InterpolateParams(query string, args []driver.Value, loc *time.Location, quoteLiteral func([]byte, string) []byte) (string, error)

func MustOpen

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

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

func MustOpenWithOptions

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

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

func Open

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

创建数据库连接

func OpenWithOptions

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

创建数据库连接

func QueryCount

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

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

func QueryMany

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

执行查询,有多行返回结果

func QueryOne

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

执行查询,有一行返回结果

func SetDefaultLocation

func SetDefaultLocation(loc *time.Location)

func SetLogDebugFunction added in v1.9.5

func SetLogDebugFunction(f LogFunction)

设置 DEBUG 打印日志函数

func SetLogWarnFunction added in v1.9.5

func SetLogWarnFunction(f LogFunction)

设置 WARN 打印日志函数

Types

type AbstractDB

type AbstractDB interface {
	AbstractDBBase
	MustBegin() *Tx
	Beginx() (*Tx, error)
}

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)
	Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
	QueryRowx(query string, args ...interface{}) *sqlx.Row
}

type AbstractTx

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

type ConnectionOptions

type ConnectionOptions interface {
	BuildDataSourceString() string
}

type DB

type DB = sqlx.DB

type LogFunction added in v1.9.5

type LogFunction = func(format string, args ...interface{})

type QueryBuilder

type QueryBuilder struct {
	// contains filtered or unexported fields
}

func NewEmptyQuery

func NewEmptyQuery() *QueryBuilder

func Table

func Table(tableName string) *QueryBuilder

func (*QueryBuilder) And

func (q *QueryBuilder) And(query string, args ...driver.Value) *QueryBuilder

func (*QueryBuilder) AndRow

func (q *QueryBuilder) AndRow(row Row) *QueryBuilder

func (*QueryBuilder) As

func (q *QueryBuilder) As(name string) *QueryBuilder

func (*QueryBuilder) Build

func (q *QueryBuilder) Build() string

func (*QueryBuilder) Clone

func (q *QueryBuilder) Clone() *QueryBuilder

func (*QueryBuilder) Count

func (q *QueryBuilder) Count(field string) *QueryBuilder

func (*QueryBuilder) Delete

func (q *QueryBuilder) Delete() *QueryBuilder

func (*QueryBuilder) Fields

func (q *QueryBuilder) Fields(fields ...string) *QueryBuilder

func (*QueryBuilder) Format

func (q *QueryBuilder) Format(query string, args ...driver.Value) string

func (*QueryBuilder) GroupBy

func (q *QueryBuilder) GroupBy(tpl string, args ...driver.Value) *QueryBuilder

func (*QueryBuilder) Having

func (q *QueryBuilder) Having(tpl string, args ...driver.Value) *QueryBuilder

func (*QueryBuilder) Init

func (q *QueryBuilder) Init(quoteIdentifier func(id string) string, quoteLiteral func([]byte, string) []byte) *QueryBuilder

func (*QueryBuilder) InnerJoin

func (q *QueryBuilder) InnerJoin(tableName string, fields ...string) *QueryBuilder

func (*QueryBuilder) Insert

func (q *QueryBuilder) Insert(row Row) *QueryBuilder

func (*QueryBuilder) InsertMany

func (q *QueryBuilder) InsertMany(rows []Row) *QueryBuilder

func (*QueryBuilder) Join

func (q *QueryBuilder) Join(tableName string, fields ...string) *QueryBuilder

func (*QueryBuilder) LeftJoin

func (q *QueryBuilder) LeftJoin(tableName string, fields ...string) *QueryBuilder

func (*QueryBuilder) Limit

func (q *QueryBuilder) Limit(n int) *QueryBuilder

func (*QueryBuilder) Location

func (q *QueryBuilder) Location(loc *time.Location) *QueryBuilder

func (*QueryBuilder) Offset added in v1.4.1

func (q *QueryBuilder) Offset(n int) *QueryBuilder

func (*QueryBuilder) On

func (q *QueryBuilder) On(condition string, args ...driver.Value) *QueryBuilder

func (*QueryBuilder) OnConflictDoUpdate

func (q *QueryBuilder) OnConflictDoUpdate(key string) *QueryBuilder

func (*QueryBuilder) OnDuplicateKeyUpdate

func (q *QueryBuilder) OnDuplicateKeyUpdate() *QueryBuilder

func (*QueryBuilder) OrderBy

func (q *QueryBuilder) OrderBy(tpl string, args ...driver.Value) *QueryBuilder

func (*QueryBuilder) QuoteIdentifier

func (q *QueryBuilder) QuoteIdentifier(id string) string

func (*QueryBuilder) Returning

func (q *QueryBuilder) Returning(fields ...string) *QueryBuilder

func (*QueryBuilder) ReturningAll

func (q *QueryBuilder) ReturningAll() *QueryBuilder

func (*QueryBuilder) RightJoin

func (q *QueryBuilder) RightJoin(tableName string, fields ...string) *QueryBuilder

func (*QueryBuilder) Select

func (q *QueryBuilder) Select(fields ...string) *QueryBuilder

func (*QueryBuilder) SelectDistinct

func (q *QueryBuilder) SelectDistinct(fields ...string) *QueryBuilder

func (*QueryBuilder) Set

func (q *QueryBuilder) Set(update string, args ...driver.Value) *QueryBuilder

func (*QueryBuilder) SetRow

func (q *QueryBuilder) SetRow(row Row) *QueryBuilder

func (*QueryBuilder) Skip

func (q *QueryBuilder) Skip(n int) *QueryBuilder

func (*QueryBuilder) Table

func (q *QueryBuilder) Table(tableName string) *QueryBuilder

func (*QueryBuilder) Update

func (q *QueryBuilder) Update() *QueryBuilder

func (*QueryBuilder) Where

func (q *QueryBuilder) Where(query string, args ...driver.Value) *QueryBuilder

func (*QueryBuilder) WhereRow

func (q *QueryBuilder) WhereRow(row Row) *QueryBuilder

type QueryCountRow

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

type Row

type Row = map[string]interface{}

func QueryManyToMap added in v1.9.0

func QueryManyToMap(tx AbstractDBBase, query string, args ...interface{}) (rows []Row, success bool)

执行查询,有多行Map返回结果,所有字段值为[]byte或nil类型,可以转换为字符串

func QueryOneToMap added in v1.9.0

func QueryOneToMap(tx AbstractDBBase, query string, args ...interface{}) (row Row, success bool)

执行查询,有一行Map返回结果,所有字段值为[]byte或nil类型,可以转换为字符串

type Tx

type Tx = sqlx.Tx

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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