Vasiliy Tolstov
dbce4a1d9e
Some checks failed
dependabot-automerge / automerge (pull_request) Has been skipped
autoapprove / autoapprove (pull_request) Failing after 4s
automerge / automerge (pull_request) Failing after 4s
codeql / analyze (go) (pull_request) Failing after 6s
prbuild / test (pull_request) Failing after 5s
prbuild / lint (pull_request) Failing after 6s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
38 lines
1002 B
Go
38 lines
1002 B
Go
package wrapper
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
//go:generate sh -c "go run gen.go > wrap_gen.go"
|
|
|
|
// namedValueToValue converts driver arguments of NamedValue format to Value format. Implemented in the same way as in
|
|
// database/sql ctxutil.go.
|
|
func namedValueToValue(named []driver.NamedValue) ([]driver.Value, error) {
|
|
dargs := make([]driver.Value, len(named))
|
|
for n, param := range named {
|
|
if len(param.Name) > 0 {
|
|
return nil, errors.New("sql: driver does not support the use of Named Parameters")
|
|
}
|
|
dargs[n] = param.Value
|
|
}
|
|
return dargs, nil
|
|
}
|
|
|
|
// namedValueToLabels convert driver arguments to interface{} slice
|
|
func namedValueToLabels(named []driver.NamedValue) []interface{} {
|
|
largs := make([]interface{}, 0, len(named)*2)
|
|
var name string
|
|
for _, param := range named {
|
|
if param.Name != "" {
|
|
name = param.Name
|
|
} else {
|
|
name = fmt.Sprintf("$%d", param.Ordinal)
|
|
}
|
|
largs = append(largs, fmt.Sprintf("%s=%s", name, param.Value))
|
|
}
|
|
return largs
|
|
}
|