query

package
v2.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: Apache-2.0 Imports: 18 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   = "!="
	LIKE       = "LIKE"
	JOIN       = "JOIN"
	INNERJOIN  = "INNER JOIN"
	LEFTJOIN   = "LEFT JOIN"
	RIGHTJOIN  = "RIGHT JOIN"
	UNION      = "UNION"
	UNIONALL   = "UNION ALL"
	DESC       = "DESC"
	ASC        = "ASC"
)

Variables

This section is empty.

Functions

func NewSqlConn

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

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 Connection

type Connection interface {
	Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	NewQuery(ctx context.Context) *QueryBuilder
	GetLastSql() Sql
	LastSql(query string, args ...interface{})
}

Connection 链接

type Epr

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

func NewEpr

func NewEpr(value string) Epr

func (Epr) ToString

func (e Epr) ToString() string

type Grammar

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

Grammar sql 语法

func (Grammar) Delete

func (g Grammar) Delete() string

func (Grammar) Insert

func (g Grammar) Insert() string

func (Grammar) InsertUpdate

func (g Grammar) InsertUpdate() string

func (Grammar) Replace

func (g Grammar) Replace() string

func (Grammar) Select

func (g Grammar) Select() string

Select 构造select

func (Grammar) ToSql

func (g Grammar) ToSql() string

func (Grammar) Update

func (g Grammar) Update() string

type NullBool

type NullBool struct{ sql.NullBool }

func NewBool

func NewBool(b bool) NullBool

func NewNullBool

func NewNullBool() NullBool

func (NullBool) Convert

func (n NullBool) Convert() string

func (NullBool) IsEmpty

func (n NullBool) IsEmpty() bool

func (NullBool) IsValid

func (n NullBool) IsValid() bool

func (NullBool) MarshalJSON

func (nb NullBool) MarshalJSON() ([]byte, error)

func (NullBool) Result

func (ns NullBool) Result() interface{}

func (*NullBool) UnmarshalJSON

func (nb *NullBool) UnmarshalJSON(b []byte) error

type NullDate

type NullDate struct {
	sql.NullString
}

NullDate 空字符串

func NewDate

func NewDate(s interface{}) NullDate

func NewNullDate

func NewNullDate() NullDate

func (NullDate) IsEmpty

func (ns NullDate) IsEmpty() bool

func (NullDate) IsValid

func (ns NullDate) IsValid() bool

func (NullDate) MarshalJSON

func (ns NullDate) MarshalJSON() ([]byte, error)

func (NullDate) Result

func (ns NullDate) Result() interface{}

func (*NullDate) Scan

func (nt *NullDate) Scan(value interface{}) error

func (*NullDate) UnmarshalJSON

func (ns *NullDate) UnmarshalJSON(b []byte) error

type NullDateTime

type NullDateTime struct {
	sql.NullString
}

NullDate 空字符串

func NewDateTime

func NewDateTime(s interface{}) NullDateTime

func NewNullDateTime

func NewNullDateTime() NullDateTime

func (NullDateTime) IsEmpty

func (ns NullDateTime) IsEmpty() bool

func (NullDateTime) IsValid

func (ns NullDateTime) IsValid() bool

func (NullDateTime) MarshalJSON

func (ns NullDateTime) MarshalJSON() ([]byte, error)

func (NullDateTime) Result

func (ns NullDateTime) Result() interface{}

func (*NullDateTime) Scan

func (nt *NullDateTime) Scan(value interface{}) error

func (*NullDateTime) UnmarshalJSON

func (ns *NullDateTime) UnmarshalJSON(b []byte) error

type NullFloat64

type NullFloat64 struct{ sql.NullFloat64 }

func NewFloat64

func NewFloat64(f float64) NullFloat64

func NewNullFloat64

func NewNullFloat64() NullFloat64

func (NullFloat64) Convert

func (n NullFloat64) Convert() string

func (NullFloat64) IsEmpty

func (n NullFloat64) IsEmpty() bool

func (NullFloat64) IsValid

func (n NullFloat64) IsValid() bool

func (NullFloat64) MarshalJSON

func (nf NullFloat64) MarshalJSON() ([]byte, error)

func (NullFloat64) Result

func (ns NullFloat64) Result() interface{}

func (*NullFloat64) UnmarshalJSON

func (nf *NullFloat64) UnmarshalJSON(b []byte) error

type NullInt32

type NullInt32 struct{ sql.NullInt32 }

func NewInt32

func NewInt32(i int32) NullInt32

func NewNullInt32

func NewNullInt32() NullInt32

func (NullInt32) Convert

func (n NullInt32) Convert() string

func (NullInt32) IsEmpty

func (n NullInt32) IsEmpty() bool

func (NullInt32) IsValid

func (n NullInt32) IsValid() bool

func (NullInt32) MarshalJSON

func (ni NullInt32) MarshalJSON() ([]byte, error)

func (NullInt32) Result

func (ns NullInt32) Result() interface{}

func (*NullInt32) UnmarshalJSON

func (ni *NullInt32) UnmarshalJSON(b []byte) error

type NullInt64

type NullInt64 struct{ sql.NullInt64 }

func NewInt64

func NewInt64(i int64) NullInt64

func NewNullInt64

func NewNullInt64() NullInt64

func (NullInt64) Convert

func (n NullInt64) Convert() string

func (NullInt64) IsEmpty

func (n NullInt64) IsEmpty() bool

func (NullInt64) IsValid

func (n NullInt64) IsValid() bool

func (NullInt64) MarshalJSON

func (ni NullInt64) MarshalJSON() ([]byte, error)

func (NullInt64) Result

func (ns NullInt64) Result() interface{}

func (*NullInt64) UnmarshalJSON

func (ni *NullInt64) UnmarshalJSON(b []byte) error

type NullString

type NullString struct {
	sql.NullString
}

NullString 空字符串

func NewNullString

func NewNullString() NullString

func NewString

func NewString(s string) NullString

func (NullString) Convert

func (n NullString) Convert() string

func (NullString) IsEmpty

func (ns NullString) IsEmpty() bool

func (NullString) IsValid

func (ns NullString) IsValid() bool

func (NullString) MarshalJSON

func (ns NullString) MarshalJSON() ([]byte, error)

func (NullString) Result

func (ns NullString) Result() interface{}

func (*NullString) UnmarshalJSON

func (ns *NullString) UnmarshalJSON(b []byte) error

type Nullable

type Nullable interface {
	IsEmpty() bool
	IsValid() bool
}

type Opt added in v2.0.7

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

type QueryBuilder

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

QueryBuilder 查询构造器

func (*QueryBuilder) Between

func (query *QueryBuilder) Between(column string, value1 interface{}, value2 interface{}) *QueryBuilder

Between 构造Between

func (*QueryBuilder) Count

func (query *QueryBuilder) Count() (int64, error)

Count ...

func (*QueryBuilder) Delete

func (query *QueryBuilder) Delete() (int64, error)

Delete .

func (*QueryBuilder) DeleteSQL

func (query *QueryBuilder) DeleteSQL() string

DeleteSQL .

func (*QueryBuilder) Distinct

func (query *QueryBuilder) Distinct() *QueryBuilder

Distinct .

func (*QueryBuilder) Equal

func (query *QueryBuilder) Equal(column string, value interface{}) *QueryBuilder

Equal 构造等于

func (*QueryBuilder) Exec

func (query *QueryBuilder) Exec(sql string, args ...interface{}) (int64, error)

Exec 原始SQl语句执行

func (*QueryBuilder) ExecSQL

func (query *QueryBuilder) ExecSQL(sql string, args ...interface{}) string

ExecSQL 原始SQl语句执行

func (*QueryBuilder) GroupBy

func (query *QueryBuilder) GroupBy(groups ...string) *QueryBuilder

GroupBy .

func (*QueryBuilder) In

func (query *QueryBuilder) In(column string, value ...interface{}) *QueryBuilder

In 构造 in语句

func (*QueryBuilder) InnerJoin

func (query *QueryBuilder) InnerJoin(tablename string, on string) *QueryBuilder

func (*QueryBuilder) Insert

func (query *QueryBuilder) Insert(data interface{}) (int64, error)

Insert 插入数据

func (*QueryBuilder) InsertSQL

func (query *QueryBuilder) InsertSQL(data interface{}) string

InsertSQL 获取SQL语句

func (*QueryBuilder) InsertUpdate

func (query *QueryBuilder) InsertUpdate(insert interface{}, update interface{}) (int64, error)

InsertUpdate ...

func (*QueryBuilder) InsertUpdateSQL

func (query *QueryBuilder) InsertUpdateSQL(insert interface{}, update interface{}) string

InsertUpdateSQL ...

func (*QueryBuilder) IsNULL

func (query *QueryBuilder) IsNULL(column string) *QueryBuilder

IsNULL .

func (*QueryBuilder) IsNotNULL

func (query *QueryBuilder) IsNotNULL(column string) *QueryBuilder

IsNotNULL .

func (*QueryBuilder) IsZero

func (query *QueryBuilder) IsZero(v reflect.Value) bool

func (*QueryBuilder) Join

func (query *QueryBuilder) Join(tablename string, on string) *QueryBuilder

Join .

func (*QueryBuilder) LeftJoin

func (query *QueryBuilder) LeftJoin(tablename string, on string) *QueryBuilder

LeftJoin .

func (*QueryBuilder) Like

func (query *QueryBuilder) Like(column string, value interface{}) *QueryBuilder

Like .

func (*QueryBuilder) Limit

func (query *QueryBuilder) Limit(limit int64) *QueryBuilder

Limit .

func (*QueryBuilder) MultiInsert

func (query *QueryBuilder) MultiInsert(datas ...interface{}) (int64, error)

MultiInsert 批量插入

func (*QueryBuilder) MultiInsertSQL

func (query *QueryBuilder) MultiInsertSQL(datas ...interface{}) string

MultiInsertSQL 批量插入

func (*QueryBuilder) NotBetween

func (query *QueryBuilder) NotBetween(column string, value1 interface{}, value2 interface{}) *QueryBuilder

NotBetween 构造不Not Between

func (*QueryBuilder) NotEqual

func (query *QueryBuilder) NotEqual(column string, value interface{}) *QueryBuilder

NotEqual 构造不等于

func (*QueryBuilder) NotIn

func (query *QueryBuilder) NotIn(column string, value ...interface{}) *QueryBuilder

NotIn .

func (*QueryBuilder) NotOrBetween

func (query *QueryBuilder) NotOrBetween(column string, value1 interface{}, value2 interface{}) *QueryBuilder

NotOrBetween 构造 Not Between OR Not Between

func (*QueryBuilder) Offset

func (query *QueryBuilder) Offset(offset int64) *QueryBuilder

Offset .

func (*QueryBuilder) OrBetween

func (query *QueryBuilder) OrBetween(column string, value1 interface{}, value2 interface{}) *QueryBuilder

OrBetween 构造 或者 Between

func (*QueryBuilder) OrEqual

func (query *QueryBuilder) OrEqual(column string, value interface{}) *QueryBuilder

OrEqual 构造或者等于

func (*QueryBuilder) OrIn

func (query *QueryBuilder) OrIn(column string, value ...interface{}) *QueryBuilder

OrIn orin语句

func (*QueryBuilder) OrIsNULL

func (query *QueryBuilder) OrIsNULL(column string) *QueryBuilder

OrIsNULL .

func (*QueryBuilder) OrIsNotNULL

func (query *QueryBuilder) OrIsNotNULL(column string) *QueryBuilder

OrIsNotNULL .

func (*QueryBuilder) OrLike

func (query *QueryBuilder) OrLike(column string, value interface{}) *QueryBuilder

OrLike .

func (*QueryBuilder) OrNotEqual

func (query *QueryBuilder) OrNotEqual(column string, value interface{}) *QueryBuilder

OrNotEqual 构造或者不等于

func (*QueryBuilder) OrNotIn

func (query *QueryBuilder) OrNotIn(column string, value ...interface{}) *QueryBuilder

OrNotIn .

func (*QueryBuilder) OrWhere

func (query *QueryBuilder) OrWhere(column string, value ...interface{}) *QueryBuilder

OrWhere 构造OR条件

func (*QueryBuilder) OrderBy

func (query *QueryBuilder) OrderBy(column string, direction string) *QueryBuilder

OrderBy .

func (*QueryBuilder) QueryRow

func (query *QueryBuilder) QueryRow(sql string, args ...interface{}) *Row

QueryRow ...

func (*QueryBuilder) QueryRowSQL

func (query *QueryBuilder) QueryRowSQL(sql string, args ...interface{}) string

QueryRowSQL ...

func (*QueryBuilder) QueryRows

func (query *QueryBuilder) QueryRows(sql string, args ...interface{}) *Rows

QueryRows ...

func (*QueryBuilder) QueryRowsSQL

func (query *QueryBuilder) QueryRowsSQL(sql string, args ...interface{}) string

QueryRowsSQL ...

func (*QueryBuilder) Replace

func (query *QueryBuilder) Replace(datas ...interface{}) (int64, error)

Replace 替换

func (*QueryBuilder) ReplaceSQL

func (query *QueryBuilder) ReplaceSQL(datas ...interface{}) string

ReplaceSQL 替换

func (*QueryBuilder) RightJoin

func (query *QueryBuilder) RightJoin(tablename string, on string) *QueryBuilder

RightJoin .

func (*QueryBuilder) Row

func (query *QueryBuilder) Row() *Row

Row 获取一条记录

func (*QueryBuilder) RowSQL

func (query *QueryBuilder) RowSQL() string

RowSQL ...

func (*QueryBuilder) Rows

func (query *QueryBuilder) Rows() *Rows

Rows 获取多条记录

func (*QueryBuilder) RowsSQL

func (query *QueryBuilder) RowsSQL() string

RowsSQL ...

func (*QueryBuilder) Select

func (query *QueryBuilder) Select(columns ...string) *QueryBuilder

Select 查询字段

func (*QueryBuilder) Skip

func (query *QueryBuilder) Skip(offset int64) *QueryBuilder

Skip .

func (*QueryBuilder) Table

func (query *QueryBuilder) Table(tablename ...string) *QueryBuilder

Table 设置操作的表名称

func (*QueryBuilder) ToSql

func (query *QueryBuilder) ToSql(method string) string

ToSql 输出SQL语句

func (*QueryBuilder) Union

func (query *QueryBuilder) Union(unions ...QueryBuilder) *QueryBuilder

Union .

func (*QueryBuilder) UnionAll

func (query *QueryBuilder) UnionAll(unions ...QueryBuilder) *QueryBuilder

UnionAll .

func (*QueryBuilder) UnionLimit

func (query *QueryBuilder) UnionLimit(limit int64) *QueryBuilder

UnionLimit .

func (*QueryBuilder) UnionOffset

func (query *QueryBuilder) UnionOffset(offset int64) *QueryBuilder

UnionOffset .

func (*QueryBuilder) UnionOrderBy

func (query *QueryBuilder) UnionOrderBy(column string, direction string) *QueryBuilder

UnionOrderBy .

func (*QueryBuilder) Update

func (query *QueryBuilder) Update(data interface{}) (int64, error)

Update 更新

func (*QueryBuilder) UpdateSQL

func (query *QueryBuilder) UpdateSQL(data interface{}) string

UpdateSQL 更新

func (*QueryBuilder) Where

func (query *QueryBuilder) Where(column string, value ...interface{}) *QueryBuilder

Where 构造条件语句

type QueryDb

type QueryDb struct {
	DB *sql.DB

	DriverName string
	Trace      bool
	Prepare    bool
	// contains filtered or unexported fields
}

QueryDb mysql 配置

func (*QueryDb) Begin

func (querydb *QueryDb) Begin() (*QueryTx, error)

Begin 开启一个事务

func (*QueryDb) Exec

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

Exec 复用执行语句

func (*QueryDb) GetLastSql

func (querydb *QueryDb) GetLastSql() Sql

GetLastSql 获取sql语句

func (*QueryDb) LastSql

func (querydb *QueryDb) LastSql(query string, args ...interface{})

func (*QueryDb) NewQuery

func (querydb *QueryDb) NewQuery(ctx context.Context) *QueryBuilder

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

func (*QueryDb) Query

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

Query 复用查询语句

func (*QueryDb) SetTrace added in v2.0.1

func (querydb *QueryDb) SetTrace(t bool)

type QueryTx

type QueryTx struct {
	TX *sql.Tx

	DriverName string
	Trace      bool
	Prepare    bool
	// contains filtered or unexported fields
}

QueryTx 事务

func (*QueryTx) Commit

func (querytx *QueryTx) Commit() error

Commit 事务提交

func (*QueryTx) Exec

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

Exec 复用执行语句

func (*QueryTx) GetLastSql

func (querytx *QueryTx) GetLastSql() Sql

GetLastSql 获取sql语句

func (*QueryTx) LastSql

func (querytx *QueryTx) LastSql(query string, args ...interface{})

func (*QueryTx) NewQuery

func (querytx *QueryTx) NewQuery(ctx context.Context) *QueryBuilder

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

func (*QueryTx) Query

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

Query 复用查询语句

func (*QueryTx) Rollback

func (querytx *QueryTx) Rollback() error

Rollback 事务回滚

type ResourceManager

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

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)

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 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 Sql

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

Sql sql语句

func (Sql) ToJson

func (sql Sql) ToJson() string

ToJson sql语句转出json

func (Sql) ToString

func (sqlRaw Sql) ToString() string

ToString sql语句转出string

Jump to

Keyboard shortcuts

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