Documentation ¶
Index ¶
- func CreateDefaultDB(config *Config) error
- func NewDB(config *Config) (db *sql.DB, err error)
- func NewStarter() *starter
- func XDB() *sql.DB
- func XFDB(f func(c *sql.DB) error) error
- type CommonDao
- func (m *CommonDao) Delete(tableName string, where map[string]interface{}) (int64, error)
- func (m *CommonDao) GetCount(tableName string, where map[string]interface{}) (int64, error)
- func (m *CommonDao) GetMulti(tableName string, where map[string]interface{}, selectField []string, ...) error
- func (m *CommonDao) GetOne(tableName string, where map[string]interface{}, selectField []string, ...) error
- func (m *CommonDao) Insert(tableName string, data []map[string]interface{}) (int64, error)
- func (m *CommonDao) InsertIgnore(tableName string, data []map[string]interface{}) (int64, error)
- func (m *CommonDao) InsertReplace(tableName string, data []map[string]interface{}) (int64, error)
- func (m *CommonDao) NewTx(ctx context.Context, options *sql.TxOptions) (*MysqlTx, error)
- func (m *CommonDao) Update(tableName string, where, data map[string]interface{}) (int64, error)
- type Config
- type MysqlTx
- func (mtx *MysqlTx) Delete(tableName string, where map[string]interface{}) (int64, error)
- func (mtx *MysqlTx) GetMulti(tableName string, where map[string]interface{}, selectField []string, ...) error
- func (mtx *MysqlTx) GetOne(tableName string, where map[string]interface{}, selectField []string, ...) error
- func (mtx *MysqlTx) Insert(tableName string, data []map[string]interface{}) (int64, error)
- func (mtx *MysqlTx) InsertIgnore(tableName string, data []map[string]interface{}) (int64, error)
- func (mtx *MysqlTx) InsertReplace(tableName string, data []map[string]interface{}) (int64, error)
- func (mtx *MysqlTx) Update(tableName string, where, data map[string]interface{}) (int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStarter ¶
func NewStarter() *starter
Types ¶
type CommonDao ¶
type CommonDao struct {
// contains filtered or unexported fields
}
通用Mysql数据访问操作
func (*CommonDao) GetMulti ¶
func (m *CommonDao) GetMulti(tableName string, where map[string]interface{}, selectField []string, results interface{}) error
根据条件获取多条数据 @param tableName string 查询的表名 @param where map[string]interface{} 查询条件 @param selectField []string 查询选择返回的字段 @param results interface{} 带表结构存储结果的指针数组,接收返回的数据,接收results应与table schema struct相对应
func (*CommonDao) GetOne ¶
func (m *CommonDao) GetOne(tableName string, where map[string]interface{}, selectField []string, result interface{}) error
以下提供通用的几个curd方法,具体构建方式可查看本目录的README
根据条件获取单条数据 @param tableName string 查询的表名 @param where map[string]interface{} 查询条件 @param selectField []string 查询选择返回的字段 @param result DaoMysqlSchema 带表结构存储结果的指针,接收返回的数据,实现DaoMysqlSchema接口
func (*CommonDao) Insert ¶
插入数据 @param tableName string 表名 @param data []map[string]interface{} 插入数据
@return LastInsertId int64 返回最新的插入id
func (*CommonDao) InsertIgnore ¶
插入数据,已存在则忽略 @param tableName string 表名 @param data []map[string]interface{} 插入数据
@return LastInsertId int64 返回最新的插入id
func (*CommonDao) InsertReplace ¶
插入数据,已存在则替换 @param tableName string 表名 @param data []map[string]interface{} 插入数据
@return LastInsertId int64 返回最新的插入id
type Config ¶
type Config struct { DbHost string // 主机地址 DbPort int64 // 主机端口 DbUser string // 用户名 DbPasswd string // 密码 DbName string // 数据库名 ConnMaxLifetime int64 // 每个连接最长生命周期,单位秒 MaxIdleConns int64 // 连接池最大闲置连接数 MaxOpenConns int64 // 连接池最大连接数 ChartSet string // 传输字符编码 AllowCleartextPasswords bool // 开发环境中设置允许明文密码通信 InterpolateParams bool // 设置允许占位符参数 Timeout int64 // 连接请求的超时时间,单位秒 ReadTimeout int64 // 读超时时间,单位秒 ParseTime bool // 将数据库的datetime时间格式转换为go time包数据类型 PING bool // 连接时PING测试 }
MysqlDB 配置
func DefaultConfig ¶
func DefaultConfig() *Config
type MysqlTx ¶
type MysqlTx struct {
// contains filtered or unexported fields
}
func (*MysqlTx) GetMulti ¶
func (mtx *MysqlTx) GetMulti(tableName string, where map[string]interface{}, selectField []string, results []interface{}) error
根据条件获取多条数据 @param tableName string 查询的表名 @param where map[string]interface{} 查询条件 @param selectField []string 查询选择返回的字段 @param results []DaoMysqlSchema 带表结构存储结果的指针数组,接收返回的数据,实现DaoMysqlSchema接口
func (*MysqlTx) GetOne ¶
func (mtx *MysqlTx) GetOne(tableName string, where map[string]interface{}, selectField []string, result interface{}) error
以下提供通用的几个基于事务的curd方法,具体构建方式可查看本目录的README
根据条件获取单条数据 @param tableName string 查询的表名 @param where map[string]interface{} 查询条件 @param selectField []string 查询选择返回的字段 @param result DaoMysqlSchema 带表结构存储结果的指针,接收返回的数据,实现DaoMysqlSchema接口
func (*MysqlTx) Insert ¶
插入数据 @param tableName string 表名 @param data []map[string]interface{} 插入数据
@return LastInsertId int64 返回最新的插入id
func (*MysqlTx) InsertIgnore ¶
插入数据,已存在则忽略 @param tableName string 表名 @param data []map[string]interface{} 插入数据
@return LastInsertId int64 返回最新的插入id
func (*MysqlTx) InsertReplace ¶
插入数据,已存在则替换 @param tableName string 表名 @param data []map[string]interface{} 插入数据
@return LastInsertId int64 返回最新的插入id