forked from scylladb/gocqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformer.go
30 lines (24 loc) · 831 Bytes
/
transformer.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
// Copyright (C) 2017 ScyllaDB
// Use of this source code is governed by a ALv2-style
// license that can be found in the LICENSE file.
package gocqlx
import (
"reflect"
"github.com/gocql/gocql"
)
// Transformer transforms the value of the named parameter to another value.
type Transformer func(name string, val interface{}) interface{}
// DefaultBindTransformer just do nothing.
//
// A custom transformer can always be set per Query.
var DefaultBindTransformer Transformer
// UnsetEmptyTransformer unsets all empty parameters.
// It helps to avoid tombstones when using the same insert/update
// statement for filled and partially filled named parameters.
var UnsetEmptyTransformer = func(name string, val interface{}) interface{} {
v := reflect.ValueOf(val)
if v.IsZero() {
return gocql.UnsetValue
}
return val
}