MCPcopy
hub / github.com/jmoiron/sqlx / bindStruct

Function bindStruct

named.go:213–225  ·  view source on GitHub ↗

bindStruct binds a named parameter query with fields from a struct argument. The rules for binding field names to parameter names follow the same conventions as for StructScan, including obeying the `db` struct tags.

(bindType int, query string, arg interface{}, m *reflectx.Mapper)

Source from the content-addressed store, hash-verified

211// The rules for binding field names to parameter names follow the same
212// conventions as for StructScan, including obeying the `db` struct tags.
213func bindStruct(bindType int, query string, arg interface{}, m *reflectx.Mapper) (string, []interface{}, error) {
214 bound, names, err := compileNamedQuery([]byte(query), bindType)
215 if err != nil {
216 return "", []interface{}{}, err
217 }
218
219 arglist, err := bindAnyArgs(names, arg, m)
220 if err != nil {
221 return "", []interface{}{}, err
222 }
223
224 return bound, arglist, nil
225}
226
227var valuesReg = regexp.MustCompile(`\)\s*(?i)VALUES\s*\(`)
228

Callers 3

bindNamedMapperFunction · 0.85
TestBindStructFunction · 0.85
BenchmarkBindStructFunction · 0.85

Calls 2

compileNamedQueryFunction · 0.85
bindAnyArgsFunction · 0.85

Tested by 2

TestBindStructFunction · 0.68
BenchmarkBindStructFunction · 0.68