query

package
v3.2.37 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BETWEEN      = "BETWEEN"
	NOTBETWEEN   = "NOT BETWEEN"
	IN           = "IN"
	NOTIN        = "NOT IN"
	AND          = "AND"
	OR           = "OR"
	ISNULL       = "IS NULL"
	ISNOTNULL    = "IS NOT NULL"
	EQUAL        = "="
	NOTEQUAL     = "!="
	GREATER      = ">"
	GREATEREQUAL = ">="
	LESS         = "<"
	LESSEQUAL    = "<="
	LIKE         = "LIKE"
	JOIN         = "JOIN"
	INNERJOIN    = "INNER JOIN"
	LEFTJOIN     = "LEFT JOIN"
	RIGHTJOIN    = "RIGHT JOIN"
	UNION        = "UNION"
	UNIONALL     = "UNION ALL"
	DESC         = "DESC"
	ASC          = "ASC"
)

BETWEEN ...

Variables

This section is empty.

Functions

func NewSQLConn added in v3.1.7

func NewSQLConn(driverName, server string, opt *Opt) (*sql.DB, error)

NewSQLConn ...

Types

type BatchError

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

A BatchError is an error that can hold multiple errors.

func (*BatchError) Add

func (be *BatchError) Add(err error)

Add adds err to be.

func (*BatchError) Err

func (be *BatchError) Err() error

Err returns an error that represents all errors.

func (*BatchError) NotNil

func (be *BatchError) NotNil() bool

NotNil checks if any error inside.

type Builder added in v3.1.9

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

Builder 查询构造器

func (*Builder) Between added in v3.1.9

func (builder *Builder) Between(column string, value1 interface{}, value2 interface{}) *Builder

Between 构造Between

func (*Builder) Count added in v3.1.9

func (builder *Builder) Count() (int64, error)

Count ...

func (*Builder) Delete added in v3.1.9

func (builder *Builder) Delete() (int64, error)

Delete .

func (*Builder) DeleteSQL added in v3.1.9

func (builder *Builder) DeleteSQL() string

DeleteSQL .

func (*Builder) Distinct added in v3.1.9

func (builder *Builder) Distinct() *Builder

Distinct .

func (*Builder) Equal added in v3.1.9

func (builder *Builder) Equal(column string, value interface{}) *Builder

Equal 构造等于

func (*Builder) Exec added in v3.1.9

func (builder *Builder) Exec(sql string, args ...interface{}) (int64, error)

Exec 原始SQl语句执行

func (*Builder) ExecSQL added in v3.1.9

func (builder *Builder) ExecSQL(sql string, args ...interface{}) string

ExecSQL 原始SQl语句执行

func (*Builder) Greater added in v3.2.8

func (builder *Builder) Greater(column string, value interface{}) *Builder

Greater 构造大于

func (*Builder) GreaterEqual added in v3.2.8

func (builder *Builder) GreaterEqual(column string, value interface{}) *Builder

Greater 构造大于等于

func (*Builder) GroupBy added in v3.1.9

func (builder *Builder) GroupBy(groups ...string) *Builder

GroupBy .

func (*Builder) In added in v3.1.9

func (builder *Builder) In(column string, value ...interface{}) *Builder

In 构造 in语句

func (*Builder) InnerJoin added in v3.1.9

func (builder *Builder) InnerJoin(tablename string, on string) *Builder

InnerJoin ...

func (*Builder) Insert added in v3.1.9

func (builder *Builder) Insert(data interface{}) (int64, error)

Insert 插入数据

func (*Builder) InsertSQL added in v3.1.9

func (builder *Builder) InsertSQL(data interface{}) string

InsertSQL 获取SQL语句

func (*Builder) InsertUpdate added in v3.1.9

func (builder *Builder) InsertUpdate(insert interface{}, update interface{}) (int64, error)

InsertUpdate ...

func (*Builder) InsertUpdateSQL added in v3.1.9

func (builder *Builder) InsertUpdateSQL(insert interface{}, update interface{}) string

InsertUpdateSQL ...

func (*Builder) IsNULL added in v3.1.9

func (builder *Builder) IsNULL(column string) *Builder

IsNULL .

func (*Builder) IsNotNULL added in v3.1.9

func (builder *Builder) IsNotNULL(column string) *Builder

IsNotNULL .

func (*Builder) IsZero added in v3.1.9

func (builder *Builder) IsZero(v reflect.Value) bool

IsZero ...

func (*Builder) Join added in v3.1.9

func (builder *Builder) Join(tablename string, on string) *Builder

Join .

func (*Builder) LeftJoin added in v3.1.9

func (builder *Builder) LeftJoin(tablename string, on string) *Builder

LeftJoin .

func (*Builder) Less added in v3.2.8

func (builder *Builder) Less(column string, value interface{}) *Builder

Greater 构造小于

func (*Builder) LessEqual added in v3.2.8

func (builder *Builder) LessEqual(column string, value interface{}) *Builder

Greater 构造小于等于

func (*Builder) Like added in v3.1.9

func (builder *Builder) Like(column string, value interface{}) *Builder

Like .

func (*Builder) Limit added in v3.1.9

func (builder *Builder) Limit(limit int64) *Builder

Limit .

func (*Builder) MultiInsert added in v3.1.9

func (builder *Builder) MultiInsert(datas ...interface{}) (int64, error)

MultiInsert 批量插入

func (*Builder) MultiInsertSQL added in v3.1.9

func (builder *Builder) MultiInsertSQL(datas ...interface{}) string

MultiInsertSQL 批量插入

func (*Builder) NotBetween added in v3.1.9

func (builder *Builder) NotBetween(column string, value1 interface{}, value2 interface{}) *Builder

NotBetween 构造不Not Between

func (*Builder) NotEqual added in v3.1.9

func (builder *Builder) NotEqual(column string, value interface{}) *Builder

NotEqual 构造不等于

func (*Builder) NotIn added in v3.1.9

func (builder *Builder) NotIn(column string, value ...interface{}) *Builder

NotIn .

func (*Builder) NotOrBetween added in v3.1.9

func (builder *Builder) NotOrBetween(column string, value1 interface{}, value2 interface{}) *Builder

NotOrBetween 构造 Not Between OR Not Between

func (*Builder) Offset added in v3.1.9

func (builder *Builder) Offset(offset int64) *Builder

Offset .

func (*Builder) OrBetween added in v3.1.9

func (builder *Builder) OrBetween(column string, value1 interface{}, value2 interface{}) *Builder

OrBetween 构造 或者 Between

func (*Builder) OrEqual added in v3.1.9

func (builder *Builder) OrEqual(column string, value interface{}) *Builder

OrEqual 构造或者等于

func (*Builder) OrIn added in v3.1.9

func (builder *Builder) OrIn(column string, value ...interface{}) *Builder

OrIn orin语句

func (*Builder) OrIsNULL added in v3.1.9

func (builder *Builder) OrIsNULL(column string) *Builder

OrIsNULL .

func (*Builder) OrIsNotNULL added in v3.1.9

func (builder *Builder) OrIsNotNULL(column string) *Builder

OrIsNotNULL .

func (*Builder) OrLike added in v3.1.9

func (builder *Builder) OrLike(column string, value interface{}) *Builder

OrLike .

func (*Builder) OrNotEqual added in v3.1.9

func (builder *Builder) OrNotEqual(column string, value interface{}) *Builder

OrNotEqual 构造或者不等于

func (*Builder) OrNotIn added in v3.1.9

func (builder *Builder) OrNotIn(column string, value ...interface{}) *Builder

OrNotIn .

func (*Builder) OrWhere added in v3.1.9

func (builder *Builder) OrWhere(column string, value ...interface{}) *Builder

OrWhere 构造OR条件

func (*Builder) OrderBy added in v3.1.9

func (builder *Builder) OrderBy(column string, direction string) *Builder

OrderBy .

func (*Builder) QueryRow added in v3.1.9

func (builder *Builder) QueryRow(sql string, args ...interface{}) *Row

QueryRow ...

func (*Builder) QueryRowSQL added in v3.1.9

func (builder *Builder) QueryRowSQL(sql string, args ...interface{}) string

QueryRowSQL ...

func (*Builder) QueryRows added in v3.1.9

func (builder *Builder) QueryRows(sql string, args ...interface{}) *Rows

QueryRows ...

func (*Builder) QueryRowsSQL added in v3.1.9

func (builder *Builder) QueryRowsSQL(sql string, args ...interface{}) string

QueryRowsSQL ...

func (*Builder) Replace added in v3.1.9

func (builder *Builder) Replace(datas ...interface{}) (int64, error)

Replace 替换

func (*Builder) ReplaceSQL added in v3.1.9

func (builder *Builder) ReplaceSQL(datas ...interface{}) string

ReplaceSQL 替换

func (*Builder) RightJoin added in v3.1.9

func (builder *Builder) RightJoin(tablename string, on string) *Builder

RightJoin .

func (*Builder) Row added in v3.1.9

func (builder *Builder) Row() *Row

Row 获取一条记录

func (*Builder) RowSQL added in v3.1.9

func (builder *Builder) RowSQL() string

RowSQL ...

func (*Builder) Rows added in v3.1.9

func (builder *Builder) Rows() *Rows

Rows 获取多条记录

func (*Builder) RowsSQL added in v3.1.9

func (builder *Builder) RowsSQL() string

RowsSQL ...

func (*Builder) Select added in v3.1.9

func (builder *Builder) Select(columns ...string) *Builder

Select 查询字段

func (*Builder) Skip added in v3.1.9

func (builder *Builder) Skip(offset int64) *Builder

Skip .

func (*Builder) Table added in v3.1.9

func (builder *Builder) Table(tableName ...string) *Builder

Table 设置操作的表名称

func (*Builder) ToSQL added in v3.1.9

func (builder *Builder) ToSQL(method string) string

ToSQL 输出SQL语句

func (*Builder) Union added in v3.1.9

func (builder *Builder) Union(unions ...Builder) *Builder

Union .

func (*Builder) UnionAll added in v3.1.9

func (builder *Builder) UnionAll(unions ...Builder) *Builder

UnionAll .

func (*Builder) UnionLimit added in v3.1.9

func (builder *Builder) UnionLimit(limit int64) *Builder

UnionLimit .

func (*Builder) UnionOffset added in v3.1.9

func (builder *Builder) UnionOffset(offset int64) *Builder

UnionOffset .

func (*Builder) UnionOrderBy added in v3.1.9

func (builder *Builder) UnionOrderBy(column string, direction string) *Builder

UnionOrderBy .

func (*Builder) Update added in v3.1.9

func (builder *Builder) Update(data interface{}) (int64, error)

Update 更新

func (*Builder) UpdateSQL added in v3.1.9

func (builder *Builder) UpdateSQL(data interface{}) string

UpdateSQL 更新

func (*Builder) Where added in v3.1.9

func (builder *Builder) Where(column string, value ...interface{}) *Builder

Where 构造条件语句

type Connection

type Connection interface {
	Exec(ctx context.Context, querySQL string, args ...interface{}) (sql.Result, error)
	Query(ctx context.Context, querySQL string, args ...interface{}) (*sql.Rows, error)
	NewBuilder(ctx context.Context) *Builder
	SQLRaw() string
	LastSQL(querySQL string, args ...interface{})
}

Connection 链接

type Epr

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

Epr ...

func NewEpr

func NewEpr(value string) Epr

NewEpr ...

func (Epr) ToString

func (e Epr) ToString() string

ToString ...

type Grammar

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

Grammar sql 语法

func (Grammar) Delete

func (g Grammar) Delete() string

Delete ...

func (Grammar) Insert

func (g Grammar) Insert() string

Insert ...

func (Grammar) InsertUpdate

func (g Grammar) InsertUpdate() string

InsertUpdate ...

func (Grammar) Replace

func (g Grammar) Replace() string

Replace ...

func (Grammar) Select

func (g Grammar) Select() string

Select 构造select

func (Grammar) ToSQL added in v3.1.8

func (g Grammar) ToSQL() string

ToSQL ...

func (Grammar) Update

func (g Grammar) Update() string

Update ...

type Opt

type Opt struct {
	MaxLifetime  time.Duration //连接池里面的连接最大存活时长
	MaxIdleTime  time.Duration //连接池里面的连接最大空闲时长
	MaxOpenConns int           //连接池最多同时打开的连接数
	MaxIdleConns int           //连接池里最大空闲连接数。必须要比maxOpenConns小
}

Opt ...

type Query added in v3.1.8

type Query struct {
	DB            *sql.DB
	SQL           SQL
	DriverName    string
	DisableMetric bool // 关闭指标采集
	DisableTrace  bool // 关闭链路追踪
	Prepare       bool
	DBName        string
	Addr          string
	Func          string // 上个函数调用的函数名称
	Path          string // 上个函数调用的函数位置
}

Query 构造查询

func (*Query) Begin added in v3.1.9

func (query *Query) Begin() (*Transaction, error)

Begin 开启一个事务

func (*Query) Exec added in v3.1.8

func (query *Query) Exec(ctx context.Context, querySQL string, args ...interface{}) (sql.Result, error)

Exec 复用执行语句

func (*Query) LastSQL added in v3.1.9

func (query *Query) LastSQL(querySQL string, args ...interface{})

LastSQL ...

func (*Query) NewBuilder added in v3.1.9

func (query *Query) NewBuilder(ctx context.Context) *Builder

NewBuilder 生成一个新的查询构造器

func (*Query) Query added in v3.1.9

func (query *Query) Query(ctx context.Context, querySQL string, args ...interface{}) (*sql.Rows, error)

Query 复用查询语句

func (*Query) SQLRaw added in v3.1.9

func (query *Query) SQLRaw() string

SQLRaw ...

type ResourceManager

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

ResourceManager A ResourceManager is a manager that used to manage resources.

func NewResourceManager

func NewResourceManager() *ResourceManager

NewResourceManager returns a ResourceManager.

func (*ResourceManager) Close

func (manager *ResourceManager) Close() error

Close closes the manager. Don't use the ResourceManager after Close() called.

func (*ResourceManager) GetResource

func (manager *ResourceManager) GetResource(key string, create func() (io.Closer, error)) (io.Closer, error)

GetResource returns the resource associated with given key.

type Row

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

Row 获取记录

func (*Row) ToArray

func (r *Row) ToArray() (result []string, err error)

ToArray get Array

func (*Row) ToInterface

func (r *Row) ToInterface() (result map[string]interface{}, err error)

ToInterface ...

func (*Row) ToMap

func (r *Row) ToMap() (result map[string]string, err error)

ToMap get Map

func (*Row) ToStruct

func (r *Row) ToStruct(st interface{}) error

ToStruct get Struct

type Rows

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

Rows get data

func (*Rows) ToArray

func (r *Rows) ToArray() (data [][]string, err error)

ToArray get Array

func (*Rows) ToInterface

func (r *Rows) ToInterface() (data []map[string]interface{}, err error)

ToInterface []map[interface{}]interface{}

func (*Rows) ToMap

func (r *Rows) ToMap() (data []map[string]string, err error)

ToMap get Map

func (*Rows) ToStruct

func (r *Rows) ToStruct(st interface{}) error

ToStruct get Struct

type SQL added in v3.1.7

type SQL struct {
	SQL      string
	Args     []interface{}
	CostTime time.Duration
}

SQL sql语句

func (SQL) ToJSON added in v3.1.8

func (sql SQL) ToJSON() string

ToJSON sql语句转出json

func (SQL) ToString added in v3.1.7

func (SQLRaw SQL) ToString() string

ToString sql语句转出string

type SharedCalls

type SharedCalls = SingleFlight

SharedCalls is an alias of SingleFlight. Deprecated: use SingleFlight.

type SingleFlight

type SingleFlight interface {
	Do(key string, fn func() (interface{}, error)) (interface{}, error)
	DoEx(key string, fn func() (interface{}, error)) (interface{}, bool, error)
}

SingleFlight lets the concurrent calls with the same key to share the call result. For example, A called F, before it's done, B called F. Then B would not execute F, and shared the result returned by F which called by A. The calls with the same key are dependent, concurrent calls share the returned values. A ------->calls F with key<------------------->returns val B --------------------->calls F with key------>returns val

func NewSharedCalls

func NewSharedCalls() SingleFlight

NewSharedCalls returns a SingleFlight. Deprecated: use NewSingleFlight.

func NewSingleFlight

func NewSingleFlight() SingleFlight

NewSingleFlight returns a SingleFlight.

type Transaction added in v3.1.9

type Transaction struct {
	Transaction   *sql.Tx
	SQL           SQL
	DriverName    string
	DisableMetric bool // 关闭指标采集
	DisableTrace  bool // 关闭链路追踪
	Prepare       bool
	DBName        string
	Addr          string
	Func          string // 上个函数调用的函数名称
	Path          string // 上个函数调用的函数位置
}

Transaction 事务

func (*Transaction) Commit added in v3.1.9

func (query *Transaction) Commit() error

Commit 事务提交

func (*Transaction) Exec added in v3.1.9

func (query *Transaction) Exec(ctx context.Context, querySQL string, args ...interface{}) (sql.Result, error)

Exec 复用执行语句

func (*Transaction) LastSQL added in v3.1.9

func (query *Transaction) LastSQL(querySQL string, args ...interface{})

LastSQL ...

func (*Transaction) NewBuilder added in v3.1.9

func (query *Transaction) NewBuilder(ctx context.Context) *Builder

NewBuilder 生成一个新的查询构造器

func (*Transaction) Query added in v3.1.9

func (query *Transaction) Query(ctx context.Context, querySQL string, args ...interface{}) (*sql.Rows, error)

Query 复用查询语句

func (*Transaction) Rollback added in v3.1.9

func (query *Transaction) Rollback() error

Rollback 事务回滚

func (*Transaction) SQLRaw added in v3.1.9

func (query *Transaction) SQLRaw() string

SQLRaw ...

Jump to

Keyboard shortcuts

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