MCPcopy Index your code
hub / github.com/upper/db / setColumnValues

Method setColumnValues

internal/sqlbuilder/template.go:278–332  ·  view source on GitHub ↗
(term interface{})

Source from the content-addressed store, hash-verified

276}
277
278func (tu *templateWithUtils) setColumnValues(term interface{}) (cv exql.ColumnValues, args []interface{}) {
279 args = []interface{}{}
280
281 switch t := term.(type) {
282 case []interface{}:
283 l := len(t)
284 for i := 0; i < l; i++ {
285 column, isString := t[i].(string)
286
287 if !isString {
288 p, q := tu.setColumnValues(t[i])
289 cv.ColumnValues = append(cv.ColumnValues, p.ColumnValues...)
290 args = append(args, q...)
291 continue
292 }
293
294 if !strings.ContainsAny(column, tu.AssignmentOperator) {
295 column = column + " " + tu.AssignmentOperator + " ?"
296 }
297
298 chunks := strings.SplitN(column, tu.AssignmentOperator, 2)
299
300 column = chunks[0]
301 format := strings.TrimSpace(chunks[1])
302
303 columnValue := exql.ColumnValue{
304 Column: exql.ColumnWithName(column),
305 Operator: tu.AssignmentOperator,
306 Value: &exql.Raw{Value: format},
307 }
308
309 ps := strings.Count(format, "?")
310 if i+ps < l {
311 for j := 0; j < ps; j++ {
312 args = append(args, t[i+j+1])
313 }
314 i = i + ps
315 } else {
316 panic(fmt.Sprintf("Format string %q has more placeholders than given arguments.", format))
317 }
318
319 cv.ColumnValues = append(cv.ColumnValues, &columnValue)
320 }
321 return cv, args
322 case *adapter.RawExpr:
323 columnValue := exql.ColumnValue{}
324 p, q := Preprocess(t.Raw(), t.Arguments())
325 columnValue.Column = &exql.Raw{Value: p}
326 cv.ColumnValues = append(cv.ColumnValues, &columnValue)
327 args = append(args, q...)
328 return cv, args
329 }
330
331 panic(fmt.Sprintf("Unknown term type %T.", term))
332}

Callers 1

SetMethod · 0.80

Calls 5

ColumnWithNameFunction · 0.92
PreprocessFunction · 0.85
RawMethod · 0.80
CountMethod · 0.65
ArgumentsMethod · 0.65

Tested by

no test coverage detected