1 Star 1 Fork 0

bigbase/pg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
hstore.go 904 Bytes
一键复制 编辑 原始数据 按行查看 历史
package types
import (
"database/sql"
"fmt"
"reflect"
)
type Hstore struct {
v reflect.Value
append AppenderFunc
scan ScannerFunc
}
var _ ValueAppender = (*Hstore)(nil)
var _ sql.Scanner = (*Hstore)(nil)
func NewHstore(vi interface{}) *Hstore {
v := reflect.ValueOf(vi)
if !v.IsValid() {
panic(fmt.Errorf("pg.Hstore(nil)"))
}
v = reflect.Indirect(v)
if v.Kind() != reflect.Map {
panic(fmt.Errorf("pg.Hstore(unsupported %s)", v.Type()))
}
return &Hstore{
v: v,
append: HstoreAppender(v.Type()),
scan: HstoreScanner(v.Type()),
}
}
func (h *Hstore) Value() interface{} {
if h.v.IsValid() {
return h.v.Interface()
}
return nil
}
func (h *Hstore) AppendValue(b []byte, quote int) ([]byte, error) {
b = h.append(b, h.v, quote)
return b, nil
}
func (h *Hstore) Scan(b interface{}) error {
if b == nil {
return h.scan(h.v, nil)
}
return h.scan(h.v, b.([]byte))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bigbase/pg.git
git@gitee.com:bigbase/pg.git
bigbase
pg
pg
v6.6.16

搜索帮助