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

Method processValues

internal/sqlbuilder/insert.go:23–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21}
22
23func (iq *inserterQuery) processValues() ([]*exql.Values, []interface{}, error) {
24 var values []*exql.Values
25 var arguments []interface{}
26
27 var mapOptions *MapOptions
28 if len(iq.enqueuedValues) > 1 {
29 mapOptions = &MapOptions{IncludeZeroed: true, IncludeNil: true}
30 }
31
32 for _, enqueuedValue := range iq.enqueuedValues {
33 if len(enqueuedValue) == 1 {
34 // If and only if we passed one argument to Values.
35 ff, vv, err := Map(enqueuedValue[0], mapOptions)
36
37 if err == nil {
38 // If we didn't have any problem with mapping we can convert it into
39 // columns and values.
40 columns, vals, args, _ := toColumnsValuesAndArguments(ff, vv)
41
42 values, arguments = append(values, vals), append(arguments, args...)
43
44 if len(iq.columns) == 0 {
45 iq.columns = append(iq.columns, columns.Columns...)
46 }
47 continue
48 }
49
50 // The only error we can expect without exiting is this argument not
51 // being a map or struct, in which case we can continue.
52 if !errors.Is(err, ErrExpectingPointerToEitherMapOrStruct) {
53 return nil, nil, err
54 }
55 }
56
57 if len(iq.columns) == 0 || len(enqueuedValue) == len(iq.columns) {
58 arguments = append(arguments, enqueuedValue...)
59
60 l := len(enqueuedValue)
61 placeholders := make([]exql.Fragment, l)
62 for i := 0; i < l; i++ {
63 placeholders[i] = sqlPlaceholder
64 }
65 values = append(values, exql.NewValueGroup(placeholders...))
66 }
67 }
68
69 return values, arguments, nil
70}
71
72func (iq *inserterQuery) statement() *exql.Statement {
73 stmt := &exql.Statement{

Callers 1

buildMethod · 0.80

Calls 3

NewValueGroupFunction · 0.92
MapFunction · 0.85

Tested by

no test coverage detected