Add DefaultUnsafe global

Setting it to true will enable Iter's `Unsafe()` behavior for all queries.
This commit is contained in:
Daniel Lohse
2020-01-15 15:11:54 +01:00
committed by Michal Jan Matczuk
parent 0f06ab790c
commit a471f98eed
2 changed files with 21 additions and 1 deletions

View File

@@ -13,6 +13,10 @@ import (
"github.com/scylladb/go-reflectx"
)
// DefaultUnsafe enables the behavior of forcing the iterator to ignore
// missing fields for all queries. See Unsafe below for more information.
var DefaultUnsafe bool
// Get is a convenience function for creating iterator and calling Get.
//
// DEPRECATED use Queryx.Get or Queryx.GetRelease.
@@ -208,7 +212,7 @@ func (iter *Iterx) StructScan(dest interface{}) bool {
iter.fields = m.TraversalsByName(v.Type(), columns)
// if we are not unsafe and are missing fields, return an error
if !iter.unsafe {
if !iter.unsafe && !DefaultUnsafe {
if f, err := missingFields(iter.fields); err != nil {
iter.err = fmt.Errorf("missing destination name %q in %T", columns[f], dest)
return false