2021-10-27 18:49:33 +03:00
|
|
|
package wrapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql/driver"
|
|
|
|
"errors"
|
2022-12-25 15:35:05 +03:00
|
|
|
"fmt"
|
2021-10-27 18:49:33 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2022-12-25 15:35:05 +03:00
|
|
|
|
2023-01-05 16:03:21 +03:00
|
|
|
// namedValueToLabels convert driver arguments to interface{} slice
|
2022-12-25 15:35:05 +03:00
|
|
|
func namedValueToLabels(named []driver.NamedValue) []interface{} {
|
2023-01-16 23:26:58 +03:00
|
|
|
largs := make([]interface{}, 0, len(named)*2)
|
2022-12-25 15:35:05 +03:00
|
|
|
var name string
|
|
|
|
for _, param := range named {
|
|
|
|
if param.Name != "" {
|
|
|
|
name = param.Name
|
|
|
|
} else {
|
|
|
|
name = fmt.Sprintf("$%d", param.Ordinal)
|
|
|
|
}
|
2023-01-16 23:26:58 +03:00
|
|
|
largs = append(largs, fmt.Sprintf("%s=%s", name, param.Value))
|
2022-12-25 15:35:05 +03:00
|
|
|
}
|
|
|
|
return largs
|
|
|
|
}
|