MCPcopy Create free account
hub / github.com/dinedal/textql / BuildValue

Function BuildValue

sqlparser/sqltypes/sqltypes.go:220–252  ·  view source on GitHub ↗
(goval interface{})

Source from the content-addressed store, hash-verified

218}
219
220func BuildValue(goval interface{}) (v Value, err error) {
221 switch bindVal := goval.(type) {
222 case nil:
223 // no op
224 case int:
225 v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))}
226 case int32:
227 v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))}
228 case int64:
229 v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))}
230 case uint:
231 v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))}
232 case uint32:
233 v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))}
234 case uint64:
235 v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))}
236 case float64:
237 v = Value{Fractional(strconv.AppendFloat(nil, bindVal, 'f', -1, 64))}
238 case string:
239 v = Value{String([]byte(bindVal))}
240 case []byte:
241 v = Value{String(bindVal)}
242 case time.Time:
243 v = Value{String([]byte(bindVal.Format("2006-01-02 15:04:05")))}
244 case Numeric, Fractional, String:
245 v = Value{bindVal.(InnerValue)}
246 case Value:
247 v = bindVal
248 default:
249 return Value{}, fmt.Errorf("unsupported bind variable type %T: %v", goval, goval)
250 }
251 return v, nil
252}
253
254// BuildNumeric builds a Numeric type that represents any whole number.
255// It normalizes the representation to ensure 1:1 mapping between the

Callers 3

UnmarshalJSONMethod · 0.85
TestTimeFunction · 0.85
TestBuildValueFunction · 0.85

Calls 4

NumericTypeAlias · 0.85
FractionalTypeAlias · 0.85
StringTypeAlias · 0.70
FormatMethod · 0.65

Tested by 2

TestTimeFunction · 0.68
TestBuildValueFunction · 0.68