本文整理汇总了Golang中github.com/youtube/vitess/go/vt/proto/query.BindVariable.Values方法的典型用法代码示例。如果您正苦于以下问题:Golang BindVariable.Values方法的具体用法?Golang BindVariable.Values怎么用?Golang BindVariable.Values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/proto/query.BindVariable
的用法示例。
在下文中一共展示了BindVariable.Values方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BindVariablesToProto3
// BindVariablesToProto3 converts internal type to proto3 BindVariable array
func BindVariablesToProto3(bindVars map[string]interface{}) (map[string]*pb.BindVariable, error) {
if len(bindVars) == 0 {
return nil, nil
}
result := make(map[string]*pb.BindVariable)
for k, v := range bindVars {
bv := new(pb.BindVariable)
switch v := v.(type) {
case []interface{}:
// This is how the list variables will normally appear.
if len(v) == 0 {
return nil, fmt.Errorf("empty list not allowed: %s", k)
}
bv.Type = sqltypes.Tuple
bv.Values = make([]*pb.Value, len(v))
values := make([]pb.Value, len(v))
for i, lv := range v {
val, err := BindVariableToValue(lv)
if err != nil {
return nil, fmt.Errorf("key: %s: %v", k, err)
}
if val.Type != sqltypes.Null {
values[i] = val
bv.Values[i] = &values[i]
}
}
case []string:
if len(v) == 0 {
return nil, fmt.Errorf("empty list not allowed: %s", k)
}
bv.Type = sqltypes.Tuple
bv.Values = make([]*pb.Value, len(v))
values := make([]pb.Value, len(v))
for i, lv := range v {
values[i].Type = sqltypes.VarChar
values[i].Value = []byte(lv)
bv.Values[i] = &values[i]
}
case [][]byte:
if len(v) == 0 {
return nil, fmt.Errorf("empty list not allowed: %s", k)
}
bv.Type = sqltypes.Tuple
bv.Values = make([]*pb.Value, len(v))
values := make([]pb.Value, len(v))
for i, lv := range v {
values[i].Type = sqltypes.VarBinary
values[i].Value = lv
bv.Values[i] = &values[i]
}
case []int:
if len(v) == 0 {
return nil, fmt.Errorf("empty list not allowed: %s", k)
}
bv.Type = sqltypes.Tuple
bv.Values = make([]*pb.Value, len(v))
values := make([]pb.Value, len(v))
for i, lv := range v {
values[i].Type = sqltypes.Int64
values[i].Value = strconv.AppendInt(nil, int64(lv), 10)
bv.Values[i] = &values[i]
}
case []int64:
if len(v) == 0 {
return nil, fmt.Errorf("empty list not allowed: %s", k)
}
bv.Type = sqltypes.Tuple
bv.Values = make([]*pb.Value, len(v))
values := make([]pb.Value, len(v))
for i, lv := range v {
values[i].Type = sqltypes.Int64
values[i].Value = strconv.AppendInt(nil, lv, 10)
bv.Values[i] = &values[i]
}
case []uint64:
if len(v) == 0 {
return nil, fmt.Errorf("empty list not allowed: %s", k)
}
bv.Type = sqltypes.Tuple
bv.Values = make([]*pb.Value, len(v))
values := make([]pb.Value, len(v))
for i, lv := range v {
values[i].Type = sqltypes.Uint64
values[i].Value = strconv.AppendUint(nil, lv, 10)
bv.Values[i] = &values[i]
}
default:
val, err := BindVariableToValue(v)
if err != nil {
return nil, fmt.Errorf("key: %s: %v", k, err)
}
bv.Type = val.Type
bv.Value = val.Value
}
result[k] = bv
}
return result, nil
}