Documentation ¶
Index ¶
- Variables
- func Addslashes(v string) string
- func CreateAnyTypeSlice(slice interface{}) ([]interface{}, bool)
- func Init(conf *gjson.Result) error
- type Builder
- func (b *Builder) Clear() *Builder
- func (b *Builder) Count() int64
- func (b *Builder) Decrement(column string, amount int64, set ...map[string]interface{}) (int64, error)
- func (b *Builder) Delete(limit ...int) (int64, error)
- func (b *Builder) Fetch(fields string, order string, group string, limit int, start int) ([]map[string]interface{}, error)
- func (b *Builder) FetchOne(field string, order string, group string, start int) string
- func (b *Builder) FetchRow(fields string, order string, group string, start int) (map[string]interface{}, error)
- func (b *Builder) FetchWithPage(fields string, order string, group string, limit int, page int) (*ResultData, error)
- func (b *Builder) Increment(column string, amount int64, set ...map[string]interface{}) (int64, error)
- func (b *Builder) Insert(set map[string]interface{}) (int64, error)
- func (b *Builder) MakeQueryString(fields string, order string, group string, limit int, start int) string
- func (b *Builder) Update(set map[string]interface{}, limit ...int) (int64, error)
- func (b *Builder) Where(cond ...interface{}) *Builder
- func (b *Builder) WhereClause(cond string) *Builder
- func (b *Builder) WhereIn(k string, in []interface{}) *Builder
- func (b *Builder) WhereMap(cond map[string]interface{}) *Builder
- func (b *Builder) WhereNotIn(k string, in []interface{}) *Builder
- type Db
- func (d *Db) Exec(query string) (sql.Result, error)
- func (d *Db) GetAll(query string) ([]map[string]interface{}, error)
- func (d *Db) GetRow(query string) (map[string]interface{}, error)
- func (d *Db) GetTablePrefix() string
- func (d *Db) Query(query string) (*sql.Rows, error)
- func (d *Db) Table(table string) *Builder
- type ResultData
- type ResultRow
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyCond = errors.New("条件不能为空")
防止在update、delete操作时,漏掉条件造成的严重后果 如果确实不需要条件,请将条件设置为 1=1
Functions ¶
func CreateAnyTypeSlice ¶ added in v0.1.6
func CreateAnyTypeSlice(slice interface{}) ([]interface{}, bool)
CreateAnyTypeSlice interface{}转为 []interface{}
func Init ¶ added in v0.1.6
配置文件格式 [
{"name": "test_w", "user": "root", "passwd": "root", "host": "127.0.0.1", "port": 3306, "dbname": "test", "charset": "utf8", "maxOpenConns": 1000}, {"name": "test1-r", "user": "root", "passwd": "root", "host": "127.0.0.1", "port": 3306, "dbname": "test1", "charset": "utf8", "maxOpenConns": 1000}
]
框架初始化时调用,请不要在业务中调用 Init 初始化数据库连接
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
查询构建器
func (*Builder) Decrement ¶
func (b *Builder) Decrement(column string, amount int64, set ...map[string]interface{}) (int64, error)
Decrement 自减 column string 自减的字段 amount int 自减的数量 set map[string]interface{} (可选参数)自减同时update的字段 返回影响的条数,错误信息
func (*Builder) Fetch ¶
func (b *Builder) Fetch(fields string, order string, group string, limit int, start int) ([]map[string]interface{}, error)
Fetch 查询并返回多条记录 field string 返回的字段 示例:"*" order string 排序 示例:"display_order DESC,id DESC" group string 分组字段 示例:"user_group" limit 结果数量 start 起始位置
func (*Builder) FetchOne ¶
FetchOne 查询并返回单个字段 field string 返回的字段 示例:"count(*) AS count" order string 排序 示例:"display_order DESC,id DESC" group string 分组字段 示例:"user_group" start 起始位置
func (*Builder) FetchRow ¶
func (b *Builder) FetchRow(fields string, order string, group string, start int) (map[string]interface{}, error)
FetchRow 查询并返回单条记录 field string 返回的字段 示例:"*" order string 排序 示例:"display_order DESC,id DESC" group string 分组字段 示例:"user_group" start 起始位置
func (*Builder) FetchWithPage ¶
func (b *Builder) FetchWithPage(fields string, order string, group string, limit int, page int) (*ResultData, error)
FetchWithPage 查询并返回多条记录,且包含分页信息 field string 返回的字段 示例:"*" order string 排序 示例:"display_order DESC,id DESC" group string 分组字段 示例:"user_group" limit 结果数量 page 第几页,从1开始
func (*Builder) Increment ¶
func (b *Builder) Increment(column string, amount int64, set ...map[string]interface{}) (int64, error)
Increment 自增 column string 自增的字段 amount int 自增的数量 set map[string]interface{} (可选参数)自增同时update的字段 返回影响的条数,错误信息
func (*Builder) MakeQueryString ¶
func (b *Builder) MakeQueryString(fields string, order string, group string, limit int, start int) string
MakeQueryString 拼接查询语句字符串
func (*Builder) Update ¶
Update 更新 set map[string]interface{} 更新的字段 limit (可选参数)限制更新limit 返回影响的条数,错误信息
func (*Builder) Where ¶ added in v0.1.6
Where 自动识别查询 推荐使用 cond string 字符串查询条件 cond map[string]interface{} map查询条件,同WhereMap cond string, []interface{} In查询条件,同WhereIn cond string, []anytype In查询条件,同WhereIn
func (*Builder) WhereMap ¶
WhereMap Map查询 会自动将map拼接为`k1`='v2' AND `k2`='v2' 的形式 map的某个key对应的值为任意类型切片时,会将此key及其对应的切片转换为IN查询条件
func (*Builder) WhereNotIn ¶ added in v0.1.6
WhereNotIn NOT IN查询
type Db ¶
type Db struct {
// contains filtered or unexported fields
}
func (*Db) GetTablePrefix ¶ added in v0.1.6
GetTablePrefix 获取表前缀
type ResultData ¶
type ResultData struct { List []map[string]interface{} `json:"list"` Count int64 `json:"count"` PerPage int `json:"pre_page"` Page int `json:"page"` PageCount int `json:"page_count"` Start int `json:"start"` Mark int `json:"mark"` }
分页返回数据 - 返回结果定义