1 Star 0 Fork 0

h79/goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
select.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2023-06-26 14:04 . option
package wrapper
import (
"gitee.com/h79/goutils/dao/option"
"strings"
)
var _ ISelect = (*Select)(nil)
type Select struct {
query []string
}
func (sel *Select) Clone() *Select {
return &Select{query: sel.query}
}
func (sel *Select) Delete(column string) *Select {
for i := range sel.query {
if sel.query[i] == column {
sel.query = append(sel.query[:i], sel.query[i+1:]...)
break
}
}
return sel
}
func (sel *Select) Add(column string) *Select {
sel.query = append(sel.query, column)
return sel
}
func (sel *Select) Query() []string {
return sel.query
}
func (sel *Select) Is() bool {
if sel == nil {
return false
}
return len(sel.query) > 0
}
func (sel *Select) Value() []interface{} {
return nil
}
func (sel *Select) Build(opts ...option.Option) string {
return sel.build(option.FullSqlExist(opts...))
}
func (sel *Select) build(full bool) string {
count := 0
builder := strings.Builder{}
for i := range sel.query {
if len(sel.query[i]) > 0 {
if count == 0 {
if full {
builder.WriteString("SELECT ")
}
} else if count > 0 {
builder.WriteByte(',')
}
builder.WriteString(sel.query[i])
count++
}
}
return builder.String()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.20.24

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385