Documentation ¶
Index ¶
- func RegisterScannableStruct(instance interface{}) error
- type StructMapping
- func (sm *StructMapping) GetAllColumnsNames() []string
- func (sm *StructMapping) GetAllFieldsPointers(s interface{}) []interface{}
- func (sm *StructMapping) GetAndUpdateOpLockFieldValue(s interface{}) (interface{}, error)
- func (sm *StructMapping) GetAutoColumnsNames() []string
- func (sm *StructMapping) GetAutoFieldsPointers(s interface{}) ([]interface{}, error)
- func (sm *StructMapping) GetAutoKeyPointer(s interface{}) (interface{}, error)
- func (sm *StructMapping) GetKeyColumnsNames() []string
- func (sm *StructMapping) GetKeyFieldsValues(s interface{}) []interface{}
- func (sm *StructMapping) GetNonAutoColumnsNames() []string
- func (sm *StructMapping) GetNonAutoFieldsValues(s interface{}) []interface{}
- func (sm *StructMapping) GetNonAutoFieldsValuesFiltered(s interface{}, filterColumns []string, isAlreadyOrdered bool) ([]string, []interface{})
- func (sm *StructMapping) GetOpLockSQLFieldName() string
- func (sm *StructMapping) GetPointersForColumns(s interface{}, columns ...string) ([]interface{}, error)
- type StructsMappingCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterScannableStruct ¶
func RegisterScannableStruct(instance interface{}) error
RegisterScannableStruct registers a struct (through an instance or pointer) as being scannable. The registered structs will not be considered as a sub structs in mappings.
Types ¶
type StructMapping ¶
type StructMapping struct { Name string // contains filtered or unexported fields }
StructMapping contains the relation between a struct and database columns.
func NewStructMapping ¶
func NewStructMapping(structInfo reflect.Type) (*StructMapping, error)
NewStructMapping builds a StructMapping with a given reflect.Type.
func (*StructMapping) GetAllColumnsNames ¶
func (sm *StructMapping) GetAllColumnsNames() []string
GetAllColumnsNames returns the names of all columns.
func (*StructMapping) GetAllFieldsPointers ¶
func (sm *StructMapping) GetAllFieldsPointers(s interface{}) []interface{}
GetAllFieldsPointers returns pointers for all fields, in the same order as GetAllColumnsNames.
func (*StructMapping) GetAndUpdateOpLockFieldValue ¶ added in v1.0.1
func (sm *StructMapping) GetAndUpdateOpLockFieldValue(s interface{}) (interface{}, error)
GetAndUpdateOpLockFieldValue returns the current value of the optimistic locking field, and update its value (unless it's an auto value updated by the database itself).
func (*StructMapping) GetAutoColumnsNames ¶
func (sm *StructMapping) GetAutoColumnsNames() []string
GetAutoColumnsNames returns the names of auto columns.
func (*StructMapping) GetAutoFieldsPointers ¶
func (sm *StructMapping) GetAutoFieldsPointers(s interface{}) ([]interface{}, error)
GetAutoFieldsPointers returns pointers of all auto fields
func (*StructMapping) GetAutoKeyPointer ¶
func (sm *StructMapping) GetAutoKeyPointer(s interface{}) (interface{}, error)
GetAutoKeyPointer returns a pointer for a key and auto columns. It will return nil if there is no such column, but no error. It will return an error if there is more than one auto and key column.
func (*StructMapping) GetKeyColumnsNames ¶
func (sm *StructMapping) GetKeyColumnsNames() []string
GetKeyColumnsNames returns the names of key columns.
func (*StructMapping) GetKeyFieldsValues ¶
func (sm *StructMapping) GetKeyFieldsValues(s interface{}) []interface{}
GetKeyFieldsValues returns values of key fields, in the same order as TestGetKeyColumnsNames.
func (*StructMapping) GetNonAutoColumnsNames ¶
func (sm *StructMapping) GetNonAutoColumnsNames() []string
GetNonAutoColumnsNames returns the names of non auto columns.
func (*StructMapping) GetNonAutoFieldsValues ¶
func (sm *StructMapping) GetNonAutoFieldsValues(s interface{}) []interface{}
GetNonAutoFieldsValues returns values of non auto fields, in the same order as GetNonAutoColumnsNames.
func (*StructMapping) GetNonAutoFieldsValuesFiltered ¶ added in v1.0.8
func (sm *StructMapping) GetNonAutoFieldsValuesFiltered(s interface{}, filterColumns []string, isAlreadyOrdered bool) ([]string, []interface{})
GetNonAutoFieldsValuesFiltered returns values of fields in filterColumns, if filterColumns is empty than returns values of non auto fields like `GetNonAutoFieldsValues` but as map
func (*StructMapping) GetOpLockSQLFieldName ¶ added in v1.0.1
func (sm *StructMapping) GetOpLockSQLFieldName() string
GetOpLockSQLFieldName returns the sql name of the optimistic locking field, or a blank string if there is none oplock field.
func (*StructMapping) GetPointersForColumns ¶
func (sm *StructMapping) GetPointersForColumns(s interface{}, columns ...string) ([]interface{}, error)
GetPointersForColumns returns pointers for the given instance and columns names.
type StructsMappingCache ¶
type StructsMappingCache struct {
// contains filtered or unexported fields
}
StructsMappingCache is a cache for StructMapping.
var Cache *StructsMappingCache
Cache is a global cache of StructMapping (StructsMappingCache). It's thread safe.
func NewStructsMappingCache ¶
func NewStructsMappingCache() *StructsMappingCache
NewStructsMappingCache builds a new StructsMappingCache.
func (*StructsMappingCache) GetOrCreateStructMapping ¶
func (smc *StructsMappingCache) GetOrCreateStructMapping(structType reflect.Type) (*StructMapping, error)
GetOrCreateStructMapping returns a StructMapping with a given type from the StructMapping cache. The StructMapping will be created if needed.