• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang query.BindVariable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/youtube/vitess/go/vt/proto/query.BindVariable的典型用法代码示例。如果您正苦于以下问题:Golang BindVariable类的具体用法?Golang BindVariable怎么用?Golang BindVariable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BindVariable类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 {
				continue
			}

			// This assumes homogenous types, but that is what we support.
			val := v[0]
			switch valt := val.(type) {
			// string and []byte are TYPE_BYTES_LIST
			case string:
				bv.Type = pb.BindVariable_TYPE_BYTES_LIST
				listArg := make([][]byte, len(v))
				for i, lv := range v {
					listArg[i] = []byte(lv.(string))
				}
				bv.ValueBytesList = listArg
			case []byte:
				bv.Type = pb.BindVariable_TYPE_BYTES_LIST
				listArg := make([][]byte, len(v))
				for i, lv := range v {
					listArg[i] = lv.([]byte)
				}
				bv.ValueBytesList = listArg

			// int, int16, int32, int64 are TYPE_INT_LIST
			case int:
				bv.Type = pb.BindVariable_TYPE_INT_LIST
				listArg := make([]int64, len(v))
				for i, lv := range v {
					listArg[i] = int64(lv.(int))
				}
				bv.ValueIntList = listArg
			case int16:
				bv.Type = pb.BindVariable_TYPE_INT_LIST
				listArg := make([]int64, len(v))
				for i, lv := range v {
					listArg[i] = int64(lv.(int16))
				}
				bv.ValueIntList = listArg
			case int32:
				bv.Type = pb.BindVariable_TYPE_INT_LIST
				listArg := make([]int64, len(v))
				for i, lv := range v {
					listArg[i] = int64(lv.(int32))
				}
				bv.ValueIntList = listArg
			case int64:
				bv.Type = pb.BindVariable_TYPE_INT_LIST
				listArg := make([]int64, len(v))
				for i, lv := range v {
					listArg[i] = lv.(int64)
				}
				bv.ValueIntList = listArg

			// uint, uint16, uint32, uint64 are TYPE_UINT_LIST
			case uint:
				bv.Type = pb.BindVariable_TYPE_UINT_LIST
				listArg := make([]uint64, len(v))
				for i, lv := range v {
					listArg[i] = uint64(lv.(uint))
				}
				bv.ValueUintList = listArg
			case uint16:
				bv.Type = pb.BindVariable_TYPE_UINT_LIST
				listArg := make([]uint64, len(v))
				for i, lv := range v {
					listArg[i] = uint64(lv.(uint16))
				}
				bv.ValueUintList = listArg
			case uint32:
				bv.Type = pb.BindVariable_TYPE_UINT_LIST
				listArg := make([]uint64, len(v))
				for i, lv := range v {
					listArg[i] = uint64(lv.(uint32))
				}
				bv.ValueUintList = listArg
			case uint64:
				bv.Type = pb.BindVariable_TYPE_UINT_LIST
				listArg := make([]uint64, len(v))
				for i, lv := range v {
					listArg[i] = lv.(uint64)
				}
				bv.ValueUintList = listArg

			// float32, float64 are TYPE_FLOAT_LIST
			case float32:
				bv.Type = pb.BindVariable_TYPE_FLOAT_LIST
				listArg := make([]float64, len(v))
				for i, lv := range v {
//.........这里部分代码省略.........
开发者ID:bayannur,项目名称:vitess,代码行数:101,代码来源:proto3.go


示例2: 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
}
开发者ID:hadmagic,项目名称:vitess,代码行数:100,代码来源:proto3.go


示例3: BoundQueryToProto3

// BoundQueryToProto3 converts internal types to proto3 BoundQuery
func BoundQueryToProto3(sql string, bindVars map[string]interface{}) *pb.BoundQuery {
	result := &pb.BoundQuery{
		Sql: []byte(sql),
	}
	if len(bindVars) > 0 {
		result.BindVariables = 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 {
					continue
				}

				// This assumes homogenous types, but that is what we support.
				val := v[0]
				switch val.(type) {
				// string and []byte are TYPE_BYTES_LIST
				case string:
					bv.Type = pb.BindVariable_TYPE_BYTES_LIST
					listArg := make([][]byte, len(v))
					for i, lv := range v {
						listArg[i] = []byte(lv.(string))
					}
					bv.ValueBytesList = listArg
				case []byte:
					bv.Type = pb.BindVariable_TYPE_BYTES_LIST
					listArg := make([][]byte, len(v))
					for i, lv := range v {
						listArg[i] = lv.([]byte)
					}
					bv.ValueBytesList = listArg

				// int, int16, int32, int64 are TYPE_INT_LIST
				case int:
					bv.Type = pb.BindVariable_TYPE_INT_LIST
					listArg := make([]int64, len(v))
					for i, lv := range v {
						listArg[i] = int64(lv.(int))
					}
					bv.ValueIntList = listArg
				case int16:
					bv.Type = pb.BindVariable_TYPE_INT_LIST
					listArg := make([]int64, len(v))
					for i, lv := range v {
						listArg[i] = int64(lv.(int16))
					}
					bv.ValueIntList = listArg
				case int32:
					bv.Type = pb.BindVariable_TYPE_INT_LIST
					listArg := make([]int64, len(v))
					for i, lv := range v {
						listArg[i] = int64(lv.(int32))
					}
					bv.ValueIntList = listArg
				case int64:
					bv.Type = pb.BindVariable_TYPE_INT_LIST
					listArg := make([]int64, len(v))
					for i, lv := range v {
						listArg[i] = lv.(int64)
					}
					bv.ValueIntList = listArg

				// uint, uint16, uint32, uint64 are TYPE_UINT_LIST
				case uint:
					bv.Type = pb.BindVariable_TYPE_UINT_LIST
					listArg := make([]uint64, len(v))
					for i, lv := range v {
						listArg[i] = uint64(lv.(uint))
					}
					bv.ValueUintList = listArg
				case uint16:
					bv.Type = pb.BindVariable_TYPE_UINT_LIST
					listArg := make([]uint64, len(v))
					for i, lv := range v {
						listArg[i] = uint64(lv.(uint16))
					}
					bv.ValueUintList = listArg
				case uint32:
					bv.Type = pb.BindVariable_TYPE_UINT_LIST
					listArg := make([]uint64, len(v))
					for i, lv := range v {
						listArg[i] = uint64(lv.(uint32))
					}
					bv.ValueUintList = listArg
				case uint64:
					bv.Type = pb.BindVariable_TYPE_UINT_LIST
					listArg := make([]uint64, len(v))
					for i, lv := range v {
						listArg[i] = lv.(uint64)
					}
					bv.ValueUintList = listArg

				// float32, float64 are TYPE_FLOAT_LIST
				case float32:
					bv.Type = pb.BindVariable_TYPE_FLOAT_LIST
					listArg := make([]float64, len(v))
					for i, lv := range v {
//.........这里部分代码省略.........
开发者ID:pranjal5215,项目名称:vitess,代码行数:101,代码来源:proto3.go



注:本文中的github.com/youtube/vitess/go/vt/proto/query.BindVariable类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap