-
Notifications
You must be signed in to change notification settings - Fork 83
/
params_map.go
36 lines (29 loc) · 1.02 KB
/
params_map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package ydb
import (
"database/sql/driver"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/bind"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/params"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
)
type wrongParameters struct {
err error
}
func (p wrongParameters) ToYDB(a *allocator.Allocator) (map[string]*Ydb.TypedValue, error) {
return nil, xerrors.WithStackTrace(p.err)
}
// ParamsFromMap build parameters from named map
//
// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
func ParamsFromMap(m map[string]any) params.Parameters {
namedParameters := make([]any, 0, len(m))
for name, val := range m {
namedParameters = append(namedParameters, driver.NamedValue{Name: name, Value: val})
}
p, err := bind.Params(namedParameters...)
if err != nil {
return wrongParameters{err: xerrors.WithStackTrace(err)}
}
return (*params.Params)(&p)
}