mapper: moved mapper to separate file, added snake case mapper
Performance is comparable to sting.ToLower BenchmarkSnakeCase-4 200000 5922 ns/op 1216 B/op 97 allocs/op BenchmarkToLower-4 300000 5418 ns/op 704 B/op 74 allocs/op
This commit is contained in:
@@ -4,18 +4,11 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/gocql/gocql"
|
||||
"github.com/jmoiron/sqlx/reflectx"
|
||||
)
|
||||
|
||||
// DefaultMapper uses `db` tag and strings.ToLower to lowercase struct field
|
||||
// names. It can be set to whatever you want, but it is encouraged to be set
|
||||
// before gocqlx is used as name-to-field mappings are cached after first
|
||||
// use on a type.
|
||||
var DefaultMapper = reflectx.NewMapperFunc("db", strings.ToLower)
|
||||
|
||||
// structOnlyError returns an error appropriate for type when a non-scannable
|
||||
// struct is expected but something else is given
|
||||
func structOnlyError(t reflect.Type) error {
|
||||
|
||||
Reference in New Issue
Block a user