Documentation ¶
Overview ¶
Package mysql @Title client.go @Description @Author haogooder @Update 2022/2/8
Package mysql @Title conf.go @Description @Author haogooder @Update 2022/2/8
Package mysql @Title elem.go @Description @Author haogooder @Update 2022/2/8
Package mysql @Title table.go @Description @Author haogooder @Update 2022/2/8
Index ¶
- Variables
- func ByteToFloat64(bytes []byte) float64
- func ByteToStr(b []byte) string
- func BytesToInt64(buf []byte) int64
- func ConvertArgs(param []ElemType) []interface{}
- func Float64ToByte(float float64) []byte
- func FormatCond(cond map[string]interface{}, delim string) (sqlCond string, param []interface{})
- func FormatFieldNameToGolangType(fieleName string) string
- func GetAllMySQLTables(db *DBase) (ret []string, err error)
- func GetMySQLAllTablesStruct(db *DBase) (ret string, err error)
- func GetMySQLTableStruct(db *DBase, tableName string) (ret string, err error)
- func Int64ToBytes(i int64) []byte
- func StrToByte(s string) []byte
- func TryBestToBool(value interface{}) (bool, error)
- func TryBestToFloat(value interface{}) (float64, error)
- func TryBestToInt64(value interface{}) (int64, error)
- func TryBestToString(value interface{}) (string, error)
- func TryBestToUint64(value interface{}) (uint64, error)
- type Basickind
- type DBase
- func (my *DBase) BeginTransaction() (*sql.Tx, error)
- func (my *DBase) Close() error
- func (my *DBase) CommitTransaction(tx *sql.Tx) error
- func (my *DBase) Conn() (*DBase, error)
- func (my *DBase) DeleteData(table string, cond map[string]interface{}) (int64, bool, error)
- func (my *DBase) Execute(sql string, args ...interface{}) (int64, bool, error)
- func (my *DBase) FetchCols(sql string, args ...interface{}) ([]ElemType, error)
- func (my *DBase) FetchCondRows(table string, cond map[string]interface{}, fields ...string) (ret []map[string]ElemType, err error)
- func (my *DBase) FetchForUpdate(table string, cond map[string]interface{}) (map[string]ElemType, error)
- func (my *DBase) FetchOne(sql string, args ...interface{}) (ret ElemType, err error)
- func (my *DBase) FetchRow(sql string, args ...interface{}) (map[string]ElemType, error)
- func (my *DBase) FetchRows(sql string, args ...interface{}) ([]map[string]ElemType, error)
- func (my *DBase) GetDB() *sql.DB
- func (my *DBase) InsertBatchData(table string, fields []string, data [][]interface{}, isIgnore bool) (int64, bool, error)
- func (my *DBase) InsertData(table string, data map[string]interface{}, isIgnore bool) (int64, bool, error)
- func (my *DBase) InsertUpdateData(table string, insert map[string]interface{}, update map[string]interface{}) (int64, bool, error)
- func (my *DBase) OpenConnNum() int
- func (my *DBase) Ping() error
- func (my *DBase) RollBackTransaction(tx *sql.Tx) error
- func (my *DBase) SetDebug(d bool)
- func (my *DBase) UpdateData(table string, data map[string]interface{}, cond map[string]interface{}) (int64, bool, error)
- type ElemType
- func (et ElemType) IsArray() bool
- func (et ElemType) IsBool() bool
- func (et ElemType) IsByteSlice() bool
- func (et ElemType) IsChan() bool
- func (et ElemType) IsComplexType() bool
- func (et ElemType) IsFloat32() bool
- func (et ElemType) IsFloat64() bool
- func (et ElemType) IsInt() bool
- func (et ElemType) IsInt16() bool
- func (et ElemType) IsInt32() bool
- func (et ElemType) IsInt64() bool
- func (et ElemType) IsInt8() bool
- func (et ElemType) IsMap() bool
- func (et ElemType) IsSimpleType() bool
- func (et ElemType) IsSlice() bool
- func (et ElemType) IsString() bool
- func (et ElemType) IsUint() bool
- func (et ElemType) IsUint16() bool
- func (et ElemType) IsUint32() bool
- func (et ElemType) IsUint64() bool
- func (et ElemType) IsUint8() bool
- func (et ElemType) Kind() reflect.Kind
- func (et ElemType) Len() (int, error)
- func (et ElemType) RawData() interface{}
- func (et ElemType) ToBool() (bool, error)
- func (et ElemType) ToFloat32() (float32, error)
- func (et ElemType) ToFloat64() (float64, error)
- func (et ElemType) ToInt() (int, error)
- func (et ElemType) ToInt16() (int16, error)
- func (et ElemType) ToInt32() (int32, error)
- func (et ElemType) ToInt64() (int64, error)
- func (et ElemType) ToInt8() (int8, error)
- func (et ElemType) ToMap() (map[ElemType]ElemType, error)
- func (et ElemType) ToSlice() ([]ElemType, error)
- func (et ElemType) ToString() string
- func (et ElemType) ToUint() (uint, error)
- func (et ElemType) ToUint16() (uint16, error)
- func (et ElemType) ToUint32() (uint32, error)
- func (et ElemType) ToUint64() (uint64, error)
- func (et ElemType) ToUint8() (uint8, error)
- type MySQLConf
- func (mc MySQLConf) SetAutoCommit(b bool) MySQLConf
- func (mc MySQLConf) SetCharset(c string) MySQLConf
- func (mc MySQLConf) SetConnMaxLiftTime(t time.Duration) MySQLConf
- func (mc MySQLConf) SetDbName(d string) MySQLConf
- func (mc MySQLConf) SetHost(h string) MySQLConf
- func (mc MySQLConf) SetMaxIdleConns(c int) MySQLConf
- func (mc MySQLConf) SetMaxOpenConns(c int) MySQLConf
- func (mc MySQLConf) SetPasswd(p string) MySQLConf
- func (mc MySQLConf) SetPort(p uint16) MySQLConf
- func (mc MySQLConf) SetTimeout(t time.Duration) MySQLConf
- func (mc MySQLConf) SetUser(u string) MySQLConf
Constants ¶
This section is empty.
Variables ¶
var ( // 一些错误信息 ErrorOverflowMaxInt64 = errors.New("this value overflow math.MaxInt64") ErrorOverflowMaxUint64 = errors.New("this value overflow math.MaxUint64") ErrorLessThanMinInt64 = errors.New("this value less than math.MinInt64") ErrorLessThanZero = errors.New("this value less than zero") ErrorBadComparisonType = errors.New("invalid type for comparison") ErrorBadComparison = errors.New("incompatible types for comparison") ErrorNoComparison = errors.New("missing argument for comparison") ErrorInvalidInputType = errors.New("invalid input type") )
Functions ¶
func FormatFieldNameToGolangType ¶
格式字段的名称
func GetMySQLAllTablesStruct ¶
生成mysql里所有表的go结构体形式
func GetMySQLTableStruct ¶
* CREATE TABLE `admin_menu` (
`menu_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '菜单ID', `menu_name` varchar(100) NOT NULL DEFAULT '' COMMENT '菜单名称', `menu_path` varchar(100) NOT NULL DEFAULT '' COMMENT '菜单路径', `icon_name` varchar(100) NOT NULL DEFAULT '' COMMENT '图标名称', `icon_color` varchar(100) NOT NULL DEFAULT '' COMMENT '图标的颜色', `parent_menu_id` int(11) NOT NULL DEFAULT '0' COMMENT '父菜单ID', `child_menu_num` int(11) NOT NULL DEFAULT '0' COMMENT '子菜单数量', `menu_sort` int(11) NOT NULL DEFAULT '0' COMMENT '同级菜单的排序值', PRIMARY KEY (`menu_id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COMMENT='菜单表'
获取表的结构
func TryBestToInt64 ¶
尽最大努力将给定的类型转换为int64 如"45.67"->45、"98.4abc3"->98、"34.87"->34
func TryBestToUint64 ¶
尽最大努力将给定的类型转换为uint64 如"45.67"->45、"98.4abc3"->98、"34.87"->34
Types ¶
type DBase ¶
MySQL连接的类
func (*DBase) DeleteData ¶
删除一条数据,返回lastAffectedRows
func (*DBase) FetchCondRows ¶
func (my *DBase) FetchCondRows(table string, cond map[string]interface{}, fields ...string) (ret []map[string]ElemType, err error)
提取多行数据 table为表名 cond为查询条件,全为and fields为要查询的字段,为空时表示查询全部
func (*DBase) FetchForUpdate ¶
func (my *DBase) FetchForUpdate(table string, cond map[string]interface{}) (map[string]ElemType, error)
执行一条select ... for update语句
func (*DBase) InsertBatchData ¶
func (my *DBase) InsertBatchData(table string, fields []string, data [][]interface{}, isIgnore bool) (int64, bool, error)
批量写入数据,返回影响行数
func (*DBase) InsertData ¶
func (my *DBase) InsertData(table string, data map[string]interface{}, isIgnore bool) (int64, bool, error)
写入一条数据,返回lastInsertId
type ElemType ¶
基本的元素类型
func (ElemType) IsComplexType ¶
是否为复合类型:slice/array/map/chan
func (ElemType) IsSimpleType ¶
是否为简单类型:int/uint/string/bool/float....
type MySQLConf ¶
type MySQLConf struct { Host string // 连接地址 Port uint16 // 端口号,默认3306 User string // 用户名 Passwd string // 密码 DbName string // DB名称 Charset string // 设置的字符编码,默认utf8 Timeout time.Duration // 连接超时时间,单位秒,默认5秒 AutoCommit bool // 是否自动提交,默认为true MaxIdleConns int // 允许最大空闲连接数,默认为2 MaxOpenConns int // 最多允许打开多少个连接,默认0不限制 ConnMaxLiftTime time.Duration // 连接的最大生存时间,默认0不限制,单位秒 }
存储MySQL的连接账号信息
func MakeMySQLConf ¶
func MakeMySQLConf() MySQLConf
func (MySQLConf) SetConnMaxLiftTime ¶
设置每个连接最长的生存周期
func (MySQLConf) SetMaxIdleConns ¶
设置允许的最多多少个空闲连接
func (MySQLConf) SetMaxOpenConns ¶
设置最多允许打开的连接数