1 Star 1 Fork 0

oshine/murphy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dbFindCond.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
Your Name 提交于 2024-08-01 19:12 . not cache
package mdb
import (
"fmt"
"gitee.com/oshine/go-murphy/core/def"
"strconv"
"strings"
"time"
)
func (b *Base) Where(where string, bind ...any) *Base {
for _, v := range bind {
var p string
switch v.(type) {
case string:
p = v.(string)
case bool:
p = strconv.FormatBool(v.(bool))
case time.Time:
p = strconv.FormatInt(v.(time.Time).UnixMilli(), 10)
default:
p = fmt.Sprintf("%v", v)
}
where = strings.Replace(where, "{?}", p, 1)
}
b._where = where
return b
}
// Order 排序,如:id desc
func (b *Base) Order(order string) *Base {
b._order = "order by " + order
return b
}
func (b *Base) Page(page int64) *Base {
b._p = page
b._ps = 20
page = (page - 1) * 20
b._limit = " limit 20" + " offset " + strconv.Itoa(int(page))
return b
}
func (b *Base) PageLimit(page, pageSize int64) *Base {
if pageSize > 100 {
println("Warnning: In func PageLimit(), pageSize no more than 100")
}
b._p = page
b._ps = pageSize
page = (page - 1) * pageSize
b._limit = " limit " + strconv.Itoa(int(pageSize)) + " offset " + strconv.Itoa(int(page))
return b
}
func (b *Base) WithCond(y def.ICond) {
str := y.Build()
p1 := str[:len(str)-3]
b._where = p1
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/oshine/murphy.git
git@gitee.com:oshine/murphy.git
oshine
murphy
murphy
v1.0.17

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385