Documentation ¶
Index ¶
- Variables
- func CloseDebug()
- func ListStructToMap(vs interface{}) ([]map[string]string, error)
- func OpenDebug()
- func SetConnMaxLifeTime(max time.Duration)
- func StructToMap(structV interface{}) (map[string]string, error)
- func ToInt64(value interface{}) (d int64)
- func ToStr(value interface{}, args ...int) (s string)
- type Client
- type ClientDNSConfigure
- type ClientExecResult
- type ClientQueryResult
- type EmptyRowsError
- type MarshalBinary
- type NetError
- type ReflectError
- type SQLError
- type Sql
- func (this *Sql) BatchInsert(table string, vs interface{}) *ClientExecResult
- func (this *Sql) BatchReplace(table string, vs interface{}) *ClientExecResult
- func (this *Sql) Delete(table string, whereFmt string, whereValue ...interface{}) *ClientExecResult
- func (this *Sql) Insert(table string, v interface{}) *ClientExecResult
- func (this *Sql) InsertOrUpdate(table string, v interface{}) *ClientExecResult
- func (this *Sql) InsertOrUpdateFields(table string, v interface{}, updateFields ...string) *ClientExecResult
- func (this *Sql) Update(table string, v interface{}, whereFmt string, whereValue ...interface{}) *ClientExecResult
- func (this *Sql) UpdateFields(table string, v interface{}, fields []string, whereFmt string, ...) *ClientExecResult
- type StrTo
- func (f StrTo) Bool() (bool, error)
- func (f *StrTo) Clear()
- func (f StrTo) Exist() bool
- func (f StrTo) Float32() (float32, error)
- func (f StrTo) Float64() (float64, error)
- func (f StrTo) Int() (int, error)
- func (f StrTo) Int16() (int16, error)
- func (f StrTo) Int32() (int32, error)
- func (f StrTo) Int64() (int64, error)
- func (f StrTo) Int8() (int8, error)
- func (f *StrTo) Set(v string)
- func (f StrTo) String() string
- func (f StrTo) Uint() (uint, error)
- func (f StrTo) Uint16() (uint16, error)
- func (f StrTo) Uint32() (uint32, error)
- func (f StrTo) Uint64() (uint64, error)
- func (f StrTo) Uint8() (uint8, error)
- type Transaction
- type UnmarshalBinary
Constants ¶
This section is empty.
Variables ¶
var Debug bool = false
Functions ¶
func ListStructToMap ¶
func SetConnMaxLifeTime ¶
* 设置每个连接的最大生存时间。如果小于等于0 则用不过期。 *
func StructToMap ¶
Types ¶
type Client ¶
type Client struct { Sql Host string Port uint32 User string Password string Database string Protocol string Config *ClientDNSConfigure // contains filtered or unexported fields }
客户端
func NewClient ¶
func NewClient(protocol string, host string, port uint32, user string, password string, database string) *Client
初始化数据库 此时并未打开连接池 只有在真实需要与数据库交互的时候才会进行连接.
func NewTcpClient ¶
初始化一个TCP客户端
func (*Client) SetMaxConn ¶
func (*Client) SetMaxIdleConn ¶
type ClientDNSConfigure ¶
type ClientDNSConfigure struct {
// contains filtered or unexported fields
}
客户端DNS配置
func NewClientDnsConfigure ¶
func NewClientDnsConfigure() *ClientDNSConfigure
func (*ClientDNSConfigure) Remove ¶
func (this *ClientDNSConfigure) Remove(k string) bool
移除设置 Remove("timeout")
func (*ClientDNSConfigure) Set ¶
func (this *ClientDNSConfigure) Set(k, v string) bool
设置一个客户端DNS设置. Set("timeout","5") 详细信息请参考golang mysql DNS语法
type ClientExecResult ¶
Client.Exec 的结果
type ClientQueryResult ¶
Client.Query 的结果
func (*ClientQueryResult) FirstToMap ¶
func (this *ClientQueryResult) FirstToMap() (map[string]string, error)
将Rows中的首行解析成一个map[string]string
func (*ClientQueryResult) FirstToStruct ¶
func (this *ClientQueryResult) FirstToStruct(v interface{}) error
将首行解析成一个Struct ,需要传递一个 struct的指针. struct 定义中使用标签 tag 来进行数据库字段映射,比如
struct { Id int `db:"id"` Name string `db:"name"` }
func (*ClientQueryResult) ToMap ¶
func (this *ClientQueryResult) ToMap() ([]map[string]string, error)
ToMap 将结果集转换为Map类型. 这个操作不进行任何类型转换. 因为这里的类型转换需要一次SQL去反射字段类型. 更多的时候会得不偿失.
func (*ClientQueryResult) ToStruct ¶
func (this *ClientQueryResult) ToStruct(containers interface{}) error
将结果集转换成一个struct 数组 var containers []Person
ToStruct(&containers) 对于struct类型,支持以下字段类型: int8
int16
int32
int64
int
uint8
uint16
uint32
uint64
uint
float32
float64
string
[]byte
type EmptyRowsError ¶
type EmptyRowsError struct { }
EmptyRowsError 未发现行
func (*EmptyRowsError) Error ¶
func (err *EmptyRowsError) Error() string
type MarshalBinary ¶
支持struct中的字段拥有更复杂的类型. 需要实现该接口才能正确的打包成string插入数据库中
type ReflectError ¶
type ReflectError struct {
// contains filtered or unexported fields
}
ReflectError 反射阶段错误
func (*ReflectError) Error ¶
func (err *ReflectError) Error() string
type Sql ¶
type Sql struct { Exec func(sqlFmt string, sqlValue ...interface{}) *ClientExecResult Query func(sqlFmt string, sqlValue ...interface{}) *ClientQueryResult }
Sql操作集
func (*Sql) BatchInsert ¶
func (this *Sql) BatchInsert(table string, vs interface{}) *ClientExecResult
批量插入 SQL语句为: INSERT INTO `%s` (field,field) VALUES (?,?),(?,?)
func (*Sql) BatchReplace ¶
func (this *Sql) BatchReplace(table string, vs interface{}) *ClientExecResult
批量重置 SQL语句为: REPLACE INTO `%s` (field,field) VALUES (?,?),(?,?)
func (*Sql) Delete ¶
func (this *Sql) Delete(table string, whereFmt string, whereValue ...interface{}) *ClientExecResult
根据Where条件删除数据
func (*Sql) Insert ¶
func (this *Sql) Insert(table string, v interface{}) *ClientExecResult
对Struct类型的支持,使用 db tag 进行数据库字段映射 对Map类型会将value转换为string.请确保map类型中只包含基本数据类型
func (*Sql) InsertOrUpdate ¶
func (this *Sql) InsertOrUpdate(table string, v interface{}) *ClientExecResult
插入或更新行(当主键已存在的时候) SQL语句为: INSERT INTO .... ON DUPLICATE KEY UPDATE .... 全部字段更新
func (*Sql) InsertOrUpdateFields ¶
func (this *Sql) InsertOrUpdateFields(table string, v interface{}, updateFields ...string) *ClientExecResult
map类型无必要使用该方法 插入或更新行(当主键已存在的时候) SQL语句为: INSERT INTO .... ON DUPLICATE KEY UPDATE .... 可以指定更新字段
func (*Sql) Update ¶
func (this *Sql) Update(table string, v interface{}, whereFmt string, whereValue ...interface{}) *ClientExecResult
对Struct类型的支持,使用 db tag 进行数据库字段映射 对Map类型会将value转换为string.请确保map类型中只包含基本数据类型 where 条件写法 id = ?
func (*Sql) UpdateFields ¶
func (this *Sql) UpdateFields(table string, v interface{}, fields []string, whereFmt string, whereValue ...interface{}) *ClientExecResult
map类型无必要使用该方法 部分字段更新 该接口的意义是struct类型为完整的数据库字段映射.但某些时候我们仅仅需要更新部分字段.此时,如果使用完整映射的进行更新操作 则更容易误覆盖. 因此提供了这个接口进行部分字段更新. fields 就是需要更新的数据库字段名称 v,whereFmt,WhereValue 等值意义不变
type UnmarshalBinary ¶
对 MarshalBinary 的反向操作