BuildConverted is like BuildValue except that it tries to convert a string or []byte to an integral if the target type is an integral. We don't perform other implicit conversions because they're unsafe.
(typ querypb.Type, goval interface{})
| 118 | // is an integral. We don't perform other implicit conversions |
| 119 | // because they're unsafe. |
| 120 | func BuildConverted(typ querypb.Type, goval interface{}) (v Value, err error) { |
| 121 | if IsIntegral(typ) { |
| 122 | switch goval := goval.(type) { |
| 123 | case []byte: |
| 124 | return ValueFromBytes(typ, goval) |
| 125 | case string: |
| 126 | return ValueFromBytes(typ, []byte(goval)) |
| 127 | case Value: |
| 128 | if goval.IsQuoted() { |
| 129 | return ValueFromBytes(typ, goval.Raw()) |
| 130 | } |
| 131 | case *querypb.BindVariable: |
| 132 | if IsQuoted(goval.Type) { |
| 133 | return ValueFromBytes(typ, goval.Value) |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | return BuildValue(goval) |
| 138 | } |
| 139 | |
| 140 | // ValueFromBytes builds a Value using typ and val. It ensures that val |
| 141 | // matches the requested type. If type is an integral it's converted to |