1 Star 1 Fork 0

bigbase/pg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
in_op.go 676 Bytes
一键复制 编辑 原始数据 按行查看 历史
Vladimir Mihailenco 提交于 2016-06-24 14:01 . Add In helper.
package types
import (
"fmt"
"reflect"
)
type InOp struct {
slice reflect.Value
append AppenderFunc
}
var _ ValueAppender = (*InOp)(nil)
func In(slice interface{}) *InOp {
v := reflect.ValueOf(slice)
if !v.IsValid() {
panic(fmt.Errorf("pg.In(nil)", v.Type()))
}
if v.Kind() != reflect.Slice {
panic(fmt.Errorf("pg.In(unsupported %s)", v.Type()))
}
return &InOp{
slice: v,
append: Appender(v.Type().Elem()),
}
}
func (in *InOp) AppendValue(b []byte, quote int) ([]byte, error) {
for i := 0; i < in.slice.Len(); i++ {
b = in.append(b, in.slice.Index(i), quote)
b = append(b, ',')
}
if in.slice.Len() > 0 {
b = b[:len(b)-1]
}
return b, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bigbase/pg.git
git@gitee.com:bigbase/pg.git
bigbase
pg
pg
v4.7.3

搜索帮助