當前位置: 首頁>>代碼示例>>Golang>>正文


Golang BindVariable.ValueUintList方法代碼示例

本文整理匯總了Golang中github.com/youtube/vitess/go/vt/proto/query.BindVariable.ValueUintList方法的典型用法代碼示例。如果您正苦於以下問題:Golang BindVariable.ValueUintList方法的具體用法?Golang BindVariable.ValueUintList怎麽用?Golang BindVariable.ValueUintList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/youtube/vitess/go/vt/proto/query.BindVariable的用法示例。


在下文中一共展示了BindVariable.ValueUintList方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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.ValueUintList方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。