// Copyright 2017-2018 gf Author(https://github.com/gogf/gf). All Rights Reserved. // // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. package gdb import ( "bytes" "errors" "fmt" "github.com/gogf/gf/internal/empty" "github.com/gogf/gf/internal/utils" "github.com/gogf/gf/os/gtime" "github.com/gogf/gf/util/gutil" "reflect" "regexp" "strings" "time" "github.com/gogf/gf/internal/structs" "github.com/gogf/gf/text/gregex" "github.com/gogf/gf/text/gstr" "github.com/gogf/gf/util/gconv" ) // apiString is the type assert api for String. type apiString interface { String() string } // apiIterator is the type assert api for Iterator. type apiIterator interface { Iterator(f func(key, value interface{}) bool) } // apiInterfaces is the type assert api for Interfaces. type apiInterfaces interface { Interfaces() []interface{} } // apiMapStrAny is the interface support for converting struct parameter to map. type apiMapStrAny interface { MapStrAny() map[string]interface{} } const ( ORM_TAG_FOR_STRUCT = "orm" ORM_TAG_FOR_UNIQUE = "unique" ORM_TAG_FOR_PRIMARY = "primary" ) var ( // quoteWordReg is the regular expression object for a word check. quoteWordReg = regexp.MustCompile(`^[a-zA-Z0-9\-_]+$`) // Priority tags for struct converting for orm field mapping. structTagPriority = append([]string{ORM_TAG_FOR_STRUCT}, gconv.StructTagPriority...) ) // ListItemValues retrieves and returns the elements of all item struct/map with key . // Note that the parameter should be type of slice which contains elements of map or struct, // or else it returns an empty slice. // // The parameter supports types like: // []map[string]interface{} // []map[string]sub-map // []struct // []struct:sub-struct // Note that the sub-map/sub-struct makes sense only if the optional parameter is given. // See gutil.ListItemValues. func ListItemValues(list interface{}, key interface{}, subKey ...interface{}) (values []interface{}) { return gutil.ListItemValues(list, key, subKey...) } // ListItemValuesUnique retrieves and returns the unique elements of all struct/map with key . // Note that the parameter should be type of slice which contains elements of map or struct, // or else it returns an empty slice. // See gutil.ListItemValuesUnique. func ListItemValuesUnique(list interface{}, key string, subKey ...interface{}) []interface{} { return gutil.ListItemValuesUnique(list, key, subKey...) } // GetInsertOperationByOption returns proper insert option with given parameter