Documentation ¶
Overview ¶
Package mapping contains neuron models mapped structures. It defines the models, fields (with options, kinds and types), relationships and field tags.
Index ¶
- Constants
- Variables
- func NamingCamel(raw string) string
- func NamingKebab(raw string) string
- func NamingLowerCamel(raw string) string
- func NamingSnake(raw string) string
- func NestedStructFields(n *NestedStruct) map[string]*NestedField
- func NestedStructMarshalType(n *NestedStruct) reflect.Type
- func NestedStructSetMarshalType(n *NestedStruct, mType reflect.Type)
- func NestedStructSetSubfield(s *NestedStruct, n *NestedField)
- func NestedStructType(n *NestedStruct) reflect.Type
- func NewReflectValueMany(m *ModelStruct) reflect.Value
- func NewReflectValueSingle(m *ModelStruct) reflect.Value
- func NewValueMany(m *ModelStruct) interface{}
- func NewValueSingle(m *ModelStruct) interface{}
- func WithDefaultNotNull(o *MapOptions)
- type BulkFieldSet
- type Collectioner
- type DatabaseIndex
- type DatabaseNamer
- type DatabaseSchemaNamer
- type FieldKind
- type FieldSet
- func (f FieldSet) Contains(sField *StructField) bool
- func (f FieldSet) ContainsFieldName(fieldName string) bool
- func (f FieldSet) Copy() FieldSet
- func (f FieldSet) Hash() (hash string)
- func (f FieldSet) Len() int
- func (f FieldSet) Less(i, j int) bool
- func (f FieldSet) Sort()
- func (f FieldSet) Swap(i, j int)
- type FieldTag
- type Fielder
- type FromSetter
- type MapOption
- func WithDatabaseNamingConvention(dbNaming NamingConvention) MapOption
- func WithDefaultDatabaseSchema(defaultSchema string) MapOption
- func WithDefaultNotNullModel(model Model) MapOption
- func WithNamingConvention(convention NamingConvention) MapOption
- func WithPluralCollections(plural bool) MapOption
- func WithPluralDatabaseCollections(plural bool) MapOption
- type MapOptions
- type Model
- type ModelMap
- func (m *ModelMap) ModelByCollection(collection string) (*ModelStruct, bool)
- func (m *ModelMap) ModelByName(name string) *ModelStruct
- func (m *ModelMap) ModelStruct(model Model) (*ModelStruct, error)
- func (m *ModelMap) Models() []*ModelStruct
- func (m *ModelMap) MustModelStruct(model Model) *ModelStruct
- func (m *ModelMap) RegisterModels(input ...Model) error
- type ModelStruct
- func (m *ModelStruct) AllowClientID() bool
- func (m *ModelStruct) Attribute(field string) (*StructField, bool)
- func (m *ModelStruct) Attributes() (attributes []*StructField)
- func (m *ModelStruct) Collection() string
- func (m *ModelStruct) CreatedAt() (*StructField, bool)
- func (m *ModelStruct) DatabaseIndexes() []*DatabaseIndex
- func (m *ModelStruct) DeletedAt() (*StructField, bool)
- func (m *ModelStruct) FieldByName(name string) (*StructField, bool)
- func (m *ModelStruct) Fields() (fields []*StructField)
- func (m *ModelStruct) ForeignKey(fieldName string) (foreignKey *StructField, ok bool)
- func (m *ModelStruct) ForeignKeys() []*StructField
- func (m *ModelStruct) HasForeignRelationships() bool
- func (m *ModelStruct) IsJoin() bool
- func (m *ModelStruct) MaxIncludedCount() int
- func (m *ModelStruct) MaxIncludedDepth() int
- func (m *ModelStruct) MustFieldByName(name string) *StructField
- func (m *ModelStruct) NamingConvention() NamingConvention
- func (m *ModelStruct) Primary() *StructField
- func (m *ModelStruct) PrivateFields() []*StructField
- func (m *ModelStruct) RelationByIndex(index int) (*StructField, error)
- func (m *ModelStruct) RelationByName(field string) (*StructField, bool)
- func (m *ModelStruct) RelationFields() (relations []*StructField)
- func (m *ModelStruct) SortScopeCount() int
- func (m *ModelStruct) StoreDelete(key interface{})
- func (m *ModelStruct) StoreGet(key interface{}) (interface{}, bool)
- func (m *ModelStruct) StoreSet(key interface{}, value interface{})
- func (m *ModelStruct) String() string
- func (m *ModelStruct) StructFieldByName(name string) (*StructField, bool)
- func (m *ModelStruct) StructFieldCount() int
- func (m *ModelStruct) StructFields() (fields []*StructField)
- func (m *ModelStruct) Type() reflect.Type
- func (m *ModelStruct) UpdatedAt() (*StructField, bool)
- type Models
- type MultiRelationer
- type Namer
- type NamingConvention
- type NestedField
- type NestedStruct
- type OrderedFieldset
- type RelationModelsLister
- type Relationship
- func (r *Relationship) ForeignKey() *StructField
- func (r *Relationship) IsManyToMany() bool
- func (r *Relationship) IsToMany() bool
- func (r *Relationship) IsToOne() bool
- func (r *Relationship) JoinModel() *ModelStruct
- func (r *Relationship) Kind() RelationshipKind
- func (r *Relationship) ManyToManyForeignKey() *StructField
- func (r *Relationship) RelatedModelStruct() *ModelStruct
- type RelationshipKind
- type RepositoryNamer
- type SingleRelationer
- type StructField
- func (s *StructField) BaseType() reflect.Type
- func (s *StructField) CanBeSorted() bool
- func (s *StructField) CodecISO8601() bool
- func (s *StructField) CodecName() string
- func (s *StructField) CodecOmitEmpty() bool
- func (s *StructField) CodecSkip() bool
- func (s *StructField) DatabaseIndexes() []*DatabaseIndex
- func (s *StructField) DatabaseNotNull() bool
- func (s *StructField) DatabaseSkip() bool
- func (s *StructField) DatabaseUnique() bool
- func (s *StructField) ExtractCustomFieldTags(fieldTag, tagSeparator, valuesSeparator string) []*FieldTag
- func (s *StructField) ExtractFieldTags(fieldTag string) []*FieldTag
- func (s *StructField) GetDereferencedType() reflect.Type
- func (s *StructField) IsArray() bool
- func (s *StructField) IsBasePtr() bool
- func (s *StructField) IsCreatedAt() bool
- func (s *StructField) IsDeletedAt() bool
- func (s *StructField) IsField() bool
- func (s *StructField) IsI18n() bool
- func (s *StructField) IsLanguage() bool
- func (s *StructField) IsMap() bool
- func (s *StructField) IsNestedField() bool
- func (s *StructField) IsNestedStruct() bool
- func (s *StructField) IsNoFilter() bool
- func (s *StructField) IsPrimary() bool
- func (s *StructField) IsPtr() bool
- func (s *StructField) IsRelationship() bool
- func (s *StructField) IsSlice() bool
- func (s *StructField) IsSortable() bool
- func (s *StructField) IsTime() bool
- func (s *StructField) IsTimePointer() bool
- func (s *StructField) IsUpdatedAt() bool
- func (s *StructField) IsZeroValue(fieldValue interface{}) bool
- func (s *StructField) Kind() FieldKind
- func (s *StructField) ModelStruct() *ModelStruct
- func (s *StructField) Name() string
- func (s *StructField) Nested() *NestedStruct
- func (s *StructField) NeuronName() string
- func (s *StructField) ReflectField() reflect.StructField
- func (s *StructField) Relationship() *Relationship
- func (s *StructField) Self() *StructField
- func (s *StructField) StoreDelete(key string)
- func (s *StructField) StoreGet(key string) (interface{}, bool)
- func (s *StructField) StoreSet(key string, value interface{})
- func (s *StructField) String() string
- func (s *StructField) Struct() *ModelStruct
- func (s *StructField) TagValues(tag string) url.Values
- type StructFieldValuer
- type ZeroChecker
Constants ¶
const ( // AnnotationFlags is the neuron model field's tag used for defining field flags. AnnotationFlags = "flags" // AnnotationHidden defines that the field should be hidden from marshaling. AnnotationHidden = "hidden" // AnnotationISO8601 sets the time field format to ISO8601. AnnotationISO8601 = "iso8601" // AnnotationOmitEmpty allows to omit marshaling this field if it's zero-value. AnnotationOmitEmpty = "omitempty" // AnnotationI18n defines that this field is internationalization ready. AnnotationI18n = "i18n" // AnnotationNoFilter is the neuron model field's flag that disallows to query filter for given field. AnnotationNoFilter = "nofilter" // AnnotationNotSortable is the neuron model field's flag that disallows to query sort on given field. AnnotationNotSortable = "nosort" // AnnotationCreatedAt is the neuron model field's flag that defines CreatedAt field. AnnotationCreatedAt = "created_at" // AnnotationDeletedAt is the neuron model field's flag that defines DeletedAt field. AnnotationDeletedAt = "deleted_at" // AnnotationUpdatedAt is the neuron model field's flag that defines UpdatedAt field. AnnotationUpdatedAt = "updated_at" )
Model field's flag tags.
const ( AnnotationPrimary = "primary" AnnotationPrimaryFull = "primary_key" AnnotationPrimaryFullS = "primarykey" AnnotationID = "id" AnnotationPrimaryShort = "pk" )
Model primary field annotation tags.
const ( AnnotationAttribute = "attr" AnnotationAttributeFull = "attribute" )
Model attribute field annotation tags.
const ( AnnotationRelation = "relation" AnnotationRelationFull = "relationship" )
Model relationship field annotation tags.
const ( // AnnotationName is the neuron model field's tag used to set the NeuronName. AnnotationName = "name" // AnnotationFieldType is the neuron model field's tag used to set the neuron field type. AnnotationFieldType = "type" // AnnotationNestedField is the model field's neuron tag that defines if the field type is of nested type. AnnotationNestedField = "nested" )
const ( AnnotationForeignKey = "foreign" AnnotationForeignKeyFull = "foreign_key" AnnotationForeignKeyFullS = "foreignkey" AnnotationForeignKeyShort = "fk" )
Model foreign key field annotation tags.
const ( // AnnotationSeparator is the symbol used to separate the sub-tags for given neuron tag. // Example: `neuron:"many2many=foreign,related_foreign"` // ^ AnnotationSeparator = "," // AnnotationTagSeparator is the symbol used to separate neuron based tags. // Example: `neuron:"type=attr;name=custom_name"` // ^ AnnotationTagSeparator = ";" // AnnotationTagEqual is the symbol used to set the values for the for given neuron tag. // Example: `neuron:"type=attr"` // ^ AnnotationTagEqual = '=' // AnnotationNestedSeparator is the symbol used as a separator for the nested fields access. // Used in included or sort fields. // Example: field.relationship. // ^ AnnotationNestedSeparator = "." // AnnotationOpenedBracket is the symbol used in filtering system // which is used to open new logical part. // Example: filter[collection][name][$operator] // ^ ^ ^ AnnotationOpenedBracket = '[' // AnnotationClosedBracket is the symbol used in filtering system // which is used to open new logical part. // Example: filter[collection][name][$operator] // ^ ^ ^ AnnotationClosedBracket = ']' )
Separators and other symbols.
const ( // MaxUint defines maximum uint value for given machine. MaxUint = ^uint(0) // MaxInt defines maximum int value for given machine. MaxInt = int(MaxUint >> 1) )
const AnnotationClientID = "client-id"
AnnotationClientID states if the primary field could be defined by the client.
const AnnotationManyToMany = "many2many"
AnnotationManyToMany is the neuron relationship field tag that states this relationship is of type many2many.
const AnnotationNeuron = "neuron"
AnnotationNeuron is the root struct field annotation tag.
Variables ¶
var ( // ErrMapping is the major error classification for the mapping package. ErrMapping = errors.New("mapping") // ErrFieldValue is an invalid field value class. ErrFieldValue = errors.Wrap(ErrMapping, "field value") // ErrRelation is the minor error classification related to mapping repositories. ErrRelation = errors.Wrap(ErrMapping, "relation") // ErrInvalidRelationValue is the error for providing invalid relation value. ErrInvalidRelationValue = errors.Wrap(ErrRelation, "invalid value") // ErrInvalidRelationField is the error for providing invalid relation field. ErrInvalidRelationField = errors.Wrap(ErrRelation, "invalid field") // ErrInvalidRelationIndex is the error for providing invalid relation index. ErrInvalidRelationIndex = errors.Wrap(ErrRelation, "invalid index") // ErrModel is the minor error classification related to the models. ErrModel = errors.Wrap(ErrMapping, "model") // ErrNilModel is an error when the input model is nil. ErrNilModel = errors.Wrap(ErrModel, "nil") // ErrModelNotMatch is an error where the model doesn't match with it's relationship. ErrModelNotMatch = errors.Wrap(ErrMapping, "not match") // ErrModelContainer is the error classification with models mapping container. ErrModelContainer = errors.Wrap(ErrModel, "container") // ErrModelDefinition is the error classification for model without fields defined. ErrModelDefinition = errors.Wrap(ErrModel, "definition") // ErrModelNotFound is the error classification for models that are not mapped. ErrModelNotFound = errors.Wrap(ErrModel, "not found") // ErrModelNotImplements is the error classification when model doesn't implement some interface. ErrModelNotImplements = errors.Wrap(ErrModel, "not implements") // ErrInvalidModelField is the error classification for invalid model field. ErrInvalidModelField = errors.Wrap(ErrModel, "invalid field") // ErrFieldNotParser is the error classification when the field is not a string parser. ErrFieldNotParser = errors.Wrap(ErrModel, "field not parser") // ErrFieldNotNullable is the error classification when the field is not nullable. ErrFieldNotNullable = errors.Wrap(ErrModel, "field not nullable") // ErrNamingConvention is an error classification with errors related with naming convention. ErrNamingConvention = errors.Wrap(ErrMapping, "naming convention") // ErrInternal is the error class for internal mapping errors. ErrInternal = errors.Wrap(errors.ErrInternal, "mapping") )
var IntegerBitSize int
IntegerBitSize is the integer bit size for given machine.
Functions ¶
func NamingCamel ¶ added in v0.15.0
NamingCamel is a Namer function that converts the 'TestingModelName' into the 'TestingModelName' format.
func NamingKebab ¶ added in v0.15.0
NamingKebab is a Namer function that converts the 'TestingModelName' into the 'testing-model-name' format.
func NamingLowerCamel ¶ added in v0.15.0
NamingLowerCamel is a Namer function that converts the 'TestingModelName' into the 'testingModelName' format.
func NamingSnake ¶ added in v0.15.0
NamingSnake is a Namer function that converts the 'TestingModelName' into the 'testing_model_name' format.
func NestedStructFields ¶ added in v0.15.0
func NestedStructFields(n *NestedStruct) map[string]*NestedField
NestedStructFields gets the nested struct fields
func NestedStructMarshalType ¶ added in v0.15.0
func NestedStructMarshalType(n *NestedStruct) reflect.Type
NestedStructMarshalType returns the marshal type for the provided nested struct
func NestedStructSetMarshalType ¶ added in v0.15.0
func NestedStructSetMarshalType(n *NestedStruct, mType reflect.Type)
NestedStructSetMarshalType sets the nested structs marshal type
func NestedStructSetSubfield ¶ added in v0.15.0
func NestedStructSetSubfield(s *NestedStruct, n *NestedField)
NestedStructSetSubfield sets the subfield for the nestedStructr
func NestedStructType ¶ added in v0.15.0
func NestedStructType(n *NestedStruct) reflect.Type
NestedStructType returns the reflect.Type of the nestedStruct
func NewReflectValueMany ¶ added in v0.15.0
func NewReflectValueMany(m *ModelStruct) reflect.Value
NewReflectValueMany creates the *[]*m.Type reflect.Models.
func NewReflectValueSingle ¶ added in v0.15.0
func NewReflectValueSingle(m *ModelStruct) reflect.Value
NewReflectValueSingle creates and returns a model's new single value.
func NewValueMany ¶ added in v0.15.0
func NewValueMany(m *ModelStruct) interface{}
NewValueMany creates and returns a model's new slice of pointers to values.
func NewValueSingle ¶ added in v0.15.0
func NewValueSingle(m *ModelStruct) interface{}
NewValueSingle creates and returns new value for the given model type.
func WithDefaultNotNull ¶ added in v0.17.0
func WithDefaultNotNull(o *MapOptions)
WithDefaultNotNull sets the default not null option for all non-pointer fields in all models.
Types ¶
type BulkFieldSet ¶ added in v0.16.0
type BulkFieldSet struct { FieldSets []FieldSet `json:"fieldSets"` Indices map[string][]int `json:"indices"` }
BulkFieldSet is the bulk query fieldset container. It stores unique
func (*BulkFieldSet) Add ¶ added in v0.16.0
func (b *BulkFieldSet) Add(fieldSet FieldSet, index int)
Add adds the model index to provided fieldset mapping. If the fieldSet was not stored yet it would be added to the slice of field sets.
func (*BulkFieldSet) CheckFieldset ¶ added in v0.16.0
func (b *BulkFieldSet) CheckFieldset(fieldSet FieldSet) bool
CheckFieldset checks if the fieldset exists in given bulk fieldset.
func (*BulkFieldSet) GetIndicesByFieldset ¶ added in v0.16.0
func (b *BulkFieldSet) GetIndicesByFieldset(fieldSet FieldSet) []int
GetIndicesByFieldset gets indices by provided fieldset.
type Collectioner ¶ added in v0.15.0
type Collectioner interface {
NeuronCollectionName() string
}
Collectioner is the interface used to get the collection name from the provided model.
type DatabaseIndex ¶ added in v0.17.0
type DatabaseIndex struct { // Name is the name of the index. Name string // Type is the database index type. Type string // Parameters are the index defined parameters. Parameters []string // Unique defines if the index is unique. Unique bool // Fields defined fields mapped for this index. Fields []*StructField }
DatabaseIndex is structure that defines database index with it's name, mapped fields, uniqueness and type.
type DatabaseNamer ¶ added in v0.17.0
type DatabaseNamer interface {
DatabaseName() string
}
DatabaseNamer is the interface used for defining model's database name - 'Table', 'Collection'.
type DatabaseSchemaNamer ¶ added in v0.17.0
type DatabaseSchemaNamer interface {
DatabaseSchemaName() string
}
DatabaseSchemaNamer is the interface that defines the optional database schema name for the model.
type FieldKind ¶
type FieldKind int
FieldKind is an enum that defines the following field type (i.e. 'primary', 'attribute').
const ( // KindUnknown is the undefined field kind. KindUnknown FieldKind = iota // KindPrimary is a 'primary' field. KindPrimary // KindAttribute is an 'attribute' field. KindAttribute // KindRelationshipSingle is a 'relationship' with single object. KindRelationshipSingle // KindRelationshipMultiple is a 'relationship' with multiple objects. KindRelationshipMultiple // KindForeignKey is the field type that is responsible for the relationships. KindForeignKey // KindNested is the field's type that is signed as Nested. KindNested )
type FieldSet ¶ added in v0.15.0
type FieldSet []*StructField
FieldSet is a slice of fields, with some basic search functions.
func (FieldSet) Contains ¶ added in v0.15.0
func (f FieldSet) Contains(sField *StructField) bool
Contains checks if given fieldset contains given 'sField'.
func (FieldSet) ContainsFieldName ¶ added in v0.15.0
ContainsFieldName checks if a field with 'fieldName' exists in given set.
type Fielder ¶ added in v0.15.0
type Fielder interface { // GetFieldZeroValue gets 'field' zero value. A zero value is an initial - non set value. GetFieldZeroValue(field *StructField) (interface{}, error) // IsFieldZero checks if the field has zero value. IsFieldZero(field *StructField) (bool, error) // SetFieldZeroValue gets 'field' zero value. A zero value is an initial - non set value. SetFieldZeroValue(field *StructField) error // GetHashableFieldValue returns hashable field value - if the function is nil - returns nil // If the field is []byte it would be converted to the string. GetHashableFieldValue(field *StructField) (interface{}, error) // GetFieldValue returns 'field' value. GetFieldValue(field *StructField) (interface{}, error) // SetFieldValue sets the 'field”s 'value'. In order to set SetFieldValue(field *StructField, value interface{}) error // GetFieldsAddress gets field's address. GetFieldsAddress(field *StructField) (interface{}, error) // ParseFieldsStringValue parses provided string value to the field's value type. I.e.: for the integer field type // when the 'value' is "1" it would convert it into int(1). // For arrays this function converts the base of it's value i.e. if a field is slice of integers and an input // 'value' is "1" it would convert it into int(1). // If the field doesn't allow to parse string value the function returns error. ParseFieldsStringValue(field *StructField, value string) (interface{}, error) }
Fielder is the interface used to get and set model field values.
type FromSetter ¶ added in v0.16.0
FromSetter is an interface that allows to set the struct field efficiently between models of the same type.
type MapOption ¶ added in v0.17.0
type MapOption func(o *MapOptions)
MapOption is a function that sets the map options.
func WithDatabaseNamingConvention ¶ added in v0.21.2
func WithDatabaseNamingConvention(dbNaming NamingConvention) MapOption
WithDatabaseNamingConvention sets the 'convention' as the naming convention for the model map.
func WithDefaultDatabaseSchema ¶ added in v0.21.2
WithDefaultDatabaseSchema sets the default database schema.
func WithDefaultNotNullModel ¶ added in v0.17.0
WithDefaultNotNullModel sets the not null as the default option for all the non pointer fields in 'model'.
func WithNamingConvention ¶ added in v0.17.0
func WithNamingConvention(convention NamingConvention) MapOption
WithNamingConvention sets the 'convention' as the naming convention for the model map.
func WithPluralCollections ¶ added in v0.21.2
WithPluralCollections defines if collections are named in plural way.
func WithPluralDatabaseCollections ¶ added in v0.21.2
WithPluralDatabaseCollections defines if the database collections are named in plural way.
type MapOptions ¶ added in v0.17.0
type MapOptions struct { DefaultNotNull bool ModelNotNull map[Model]struct{} NamingConvention NamingConvention DBNamingConvention NamingConvention PluralCollections bool DatabasePluralCollections bool DefaultDatabaseSchema string }
MapOptions are the options for the model map.
type Model ¶ added in v0.15.0
type Model interface { // GetPrimaryKeyStringValue gets the primary key string value. GetPrimaryKeyStringValue() (string, error) // GetPrimaryKeyValue returns the primary key field value. GetPrimaryKeyValue() interface{} // GetPrimaryKeyHashableValue returns the primary key field value. GetPrimaryKeyHashableValue() interface{} // GetPrimaryKeyZeroValue gets the primary key zero (non set) value. GetPrimaryKeyZeroValue() interface{} // GetPrimaryKeyAddress GetPrimaryKeyAddress() interface{} // IsPrimaryKeyZero checks if the primary key value is zero. IsPrimaryKeyZero() bool // SetPrimaryKeyValue sets the primary key field value to 'src'. SetPrimaryKeyValue(src interface{}) error // SetPrimaryKeyStringValue sets the primary key field value from the string 'src'. SetPrimaryKeyStringValue(src string) error }
Model is the interface used for getting and setting model primary values.
func NewModel ¶ added in v0.15.0
func NewModel(m *ModelStruct) Model
NewModel creates new model instance.
type ModelMap ¶ added in v0.15.0
type ModelMap struct { sync.RWMutex Options *MapOptions // contains filtered or unexported fields }
ModelMap contains mapped models ( as reflect.Type ) to its ModelStruct representation.
func New ¶ added in v0.21.0
NewModelMap creates new model map with default 'namerFunc' and a controller config 'c'.
func (*ModelMap) ModelByCollection ¶ added in v0.21.0
func (m *ModelMap) ModelByCollection(collection string) (*ModelStruct, bool)
GetByCollection gets *ModelStruct by the 'collection'.
func (*ModelMap) ModelByName ¶ added in v0.15.0
func (m *ModelMap) ModelByName(name string) *ModelStruct
ModelByName gets the model by it's struct name.
func (*ModelMap) ModelStruct ¶ added in v0.21.0
func (m *ModelMap) ModelStruct(model Model) (*ModelStruct, error)
GetModelStruct gets the model from the model map.
func (*ModelMap) Models ¶ added in v0.15.0
func (m *ModelMap) Models() []*ModelStruct
Models returns all models set within given model map.
func (*ModelMap) MustModelStruct ¶ added in v0.16.0
func (m *ModelMap) MustModelStruct(model Model) *ModelStruct
MustModelStruct gets the model from the model map.
func (*ModelMap) RegisterModels ¶ added in v0.15.0
RegisterModels registers the model within the model map container.
type ModelStruct ¶
type ModelStruct struct { // DatabaseSchemaName gets the database schema name. DatabaseSchemaName string // DatabaseName gets the database model equivalent (e.g. table) name. DatabaseName string // contains filtered or unexported fields }
ModelStruct is the structure definition for the imported models. It contains all the collection name, fields, config, store and a model type.
func (*ModelStruct) AllowClientID ¶ added in v0.15.0
func (m *ModelStruct) AllowClientID() bool
AllowClientID checks if the model allows client settable primary key values.
func (*ModelStruct) Attribute ¶ added in v0.15.0
func (m *ModelStruct) Attribute(field string) (*StructField, bool)
Attribute returns the attribute for the provided ModelStruct. If the attribute doesn't exists returns nil field and false.
func (*ModelStruct) Attributes ¶ added in v0.15.0
func (m *ModelStruct) Attributes() (attributes []*StructField)
Attributes returns all field's with kind - 'KindAttribute' for given model.
func (*ModelStruct) Collection ¶
func (m *ModelStruct) Collection() string
Collection returns model's collection.
func (*ModelStruct) CreatedAt ¶ added in v0.15.0
func (m *ModelStruct) CreatedAt() (*StructField, bool)
CreatedAt gets the 'CreatedAt' field for the model struct.
func (*ModelStruct) DatabaseIndexes ¶ added in v0.17.0
func (m *ModelStruct) DatabaseIndexes() []*DatabaseIndex
DatabaseIndexes gets database indexes for given field.
func (*ModelStruct) DeletedAt ¶ added in v0.15.0
func (m *ModelStruct) DeletedAt() (*StructField, bool)
DeletedAt gets the 'DeletedAt' field for the model struct.
func (*ModelStruct) FieldByName ¶
func (m *ModelStruct) FieldByName(name string) (*StructField, bool)
FieldByName returns structField by it's 'name'. It matches both reflect.StructField.Name and NeuronName.
func (*ModelStruct) Fields ¶
func (m *ModelStruct) Fields() (fields []*StructField)
Fields gets the model's primary, attribute and foreign key fields.
func (*ModelStruct) ForeignKey ¶
func (m *ModelStruct) ForeignKey(fieldName string) (foreignKey *StructField, ok bool)
ForeignKey checks and returns model's foreign key field. The 'fk' foreign key field name may be a Neuron name or Golang StructField name.
func (*ModelStruct) ForeignKeys ¶ added in v0.15.0
func (m *ModelStruct) ForeignKeys() []*StructField
ForeignKeys return ForeignKey struct fields for the given model.
func (*ModelStruct) HasForeignRelationships ¶ added in v0.15.0
func (m *ModelStruct) HasForeignRelationships() bool
HasForeignRelationships defines if the model has any foreign relationships (not a BelongsTo relationship).
func (*ModelStruct) IsJoin ¶ added in v0.15.0
func (m *ModelStruct) IsJoin() bool
IsJoin defines if the model is a join table for the Many2Many relationship.
func (*ModelStruct) MaxIncludedCount ¶ added in v0.15.0
func (m *ModelStruct) MaxIncludedCount() int
MaxIncludedCount gets the maximum included field number for given model.
func (*ModelStruct) MaxIncludedDepth ¶ added in v0.15.0
func (m *ModelStruct) MaxIncludedDepth() int
MaxIncludedDepth gets the maximum included field depth for the queries.
func (*ModelStruct) MustFieldByName ¶ added in v0.16.0
func (m *ModelStruct) MustFieldByName(name string) *StructField
MustFieldByName returns structField by it's 'name'. It matches both reflect.StructField.Name and NeuronName. If the field is not found returns nil value.
func (*ModelStruct) NamingConvention ¶ added in v0.16.0
func (m *ModelStruct) NamingConvention() NamingConvention
NamingConvention returns namer func for the given Model.
func (*ModelStruct) Primary ¶
func (m *ModelStruct) Primary() *StructField
Primary returns model's primary field StructField.
func (*ModelStruct) PrivateFields ¶ added in v0.15.0
func (m *ModelStruct) PrivateFields() []*StructField
PrivateFields gets model's private struct fields.
func (*ModelStruct) RelationByIndex ¶ added in v0.16.0
func (m *ModelStruct) RelationByIndex(index int) (*StructField, error)
RelationByIndex gets the relation by provided 'index'.
func (*ModelStruct) RelationByName ¶ added in v0.15.0
func (m *ModelStruct) RelationByName(field string) (*StructField, bool)
RelationByName gets the relationship field for the provided string The 'rel' relationship field name may be a Neuron or Golang StructField name. If the relationship field doesn't exists returns nil and false
func (*ModelStruct) RelationFields ¶ added in v0.15.0
func (m *ModelStruct) RelationFields() (relations []*StructField)
RelationFields gets all model's relationship fields.
func (*ModelStruct) SortScopeCount ¶ added in v0.15.0
func (m *ModelStruct) SortScopeCount() int
SortScopeCount returns the count of the sort fields.
func (*ModelStruct) StoreDelete ¶
func (m *ModelStruct) StoreDelete(key interface{})
StoreDelete deletes the store's value at 'key'.
func (*ModelStruct) StoreGet ¶
func (m *ModelStruct) StoreGet(key interface{}) (interface{}, bool)
StoreGet gets the value from the store at the key: 'key'.
func (*ModelStruct) StoreSet ¶
func (m *ModelStruct) StoreSet(key interface{}, value interface{})
StoreSet sets into the store the value 'value' for given 'key'.
func (*ModelStruct) String ¶ added in v0.15.0
func (m *ModelStruct) String() string
String implements fmt.Stringer interface.
func (*ModelStruct) StructFieldByName ¶ added in v0.16.0
func (m *ModelStruct) StructFieldByName(name string) (*StructField, bool)
StructFieldByName gets the struct field by it's neuron name or go field name.
func (*ModelStruct) StructFieldCount ¶ added in v0.15.0
func (m *ModelStruct) StructFieldCount() int
StructFieldCount returns the number of struct fields.
func (*ModelStruct) StructFields ¶
func (m *ModelStruct) StructFields() (fields []*StructField)
StructFields return all the StructFields used in the ModelStruct
func (*ModelStruct) Type ¶
func (m *ModelStruct) Type() reflect.Type
Type returns model's reflect.Type.
func (*ModelStruct) UpdatedAt ¶ added in v0.15.0
func (m *ModelStruct) UpdatedAt() (*StructField, bool)
UpdatedAt gets the 'UpdatedAt' field for the model struct.
type Models ¶ added in v0.19.0
type Models []Model
Models is the slice of models.
func (Models) PrimaryKeyStringValues ¶ added in v0.19.0
PrimaryKeyStringValues gets primary key string values for given models.
func (Models) PrimaryKeyValues ¶ added in v0.19.0
func (m Models) PrimaryKeyValues() (values []interface{})
PrimaryKeyValues gets primary key values for provided models.
type MultiRelationer ¶ added in v0.15.0
type MultiRelationer interface { // AddRelationModel adds 'model' to the given 'relation' slice. AddRelationModel(relation *StructField, model Model) error // GetRelationModels gets the model values for the 'relation' field. GetRelationModels(relation *StructField) ([]Model, error) // GetRelationModelAt gets the 'relation' single model value at 'index' in the slice. GetRelationModelAt(relation *StructField, index int) (Model, error) // GetRelationLen gets the length of the 'relation' field. GetRelationLen(relation *StructField) (int, error) // SetRelationModels sets the 'relation' 'models' instances to the given root model. SetRelationModels(relation *StructField, models ...Model) error }
MultiRelationer is the interface used to operate on the model with relationship of 'many' type like: HasMany or Many2Many.
type Namer ¶ added in v0.15.0
Namer is the function that change the name with some prepared formatting.
type NamingConvention ¶ added in v0.16.0
type NamingConvention int
NamingConvention is the model mapping naming convention.
const ( // SnakeCase is the naming convention where all words are in lower case letters separated by the '_' character. // i.e.: naming_convention SnakeCase NamingConvention // CamelCase is the naming convention where words are not separated by any character or space and each word starts // with a capital letter. // i.e.: NamingConvention CamelCase // LowerCamelCase is the naming convention where words are not separated by any character or space and all but first words starts // with a capital letter. // i.e.: namingConvention LowerCamelCase // KebabCase is the naming convention where all words are in lower case letters separated by the '-' character. // i.e.: naming-convention KebabCase )
Enum values for the naming conventions.
func (NamingConvention) Namer ¶ added in v0.16.0
func (n NamingConvention) Namer(raw string) string
Namer gets the namer function for the 'raw' value.
func (*NamingConvention) Parse ¶ added in v0.16.0
func (n *NamingConvention) Parse(name string) error
Parse parses the naming convention from 'name'.
func (NamingConvention) String ¶ added in v0.16.0
func (n NamingConvention) String() string
String implements fmt.Stringer interface.
type NestedField ¶
type NestedField struct {
// contains filtered or unexported fields
}
NestedField is the field within the NestedStruct
func NestedStructSubField ¶ added in v0.15.0
func NestedStructSubField(n *NestedStruct, field string) (*NestedField, bool)
NestedStructSubField returns the NestedStruct subfield if exists.
func (*NestedField) NestedAttribute ¶ added in v0.15.0
func (n *NestedField) NestedAttribute() *StructField
NestedAttribute returns nested Select Attribute
func (*NestedField) NestedFieldRoot ¶ added in v0.15.0
func (n *NestedField) NestedFieldRoot() *NestedStruct
NestedFieldRoot returns the root of the NestedField
func (*NestedField) Self ¶ added in v0.15.0
func (n *NestedField) Self() *StructField
Self is the relation to it's struct field.
func (*NestedField) SelfNested ¶ added in v0.15.0
func (n *NestedField) SelfNested() *NestedField
SelfNested returns the pointer to itself.
func (*NestedField) StructField ¶
func (n *NestedField) StructField() *StructField
StructField returns the structField
type NestedStruct ¶
type NestedStruct struct {
// contains filtered or unexported fields
}
NestedStruct is the field StructField that is composed from different abstraction then the basic data types. It may contain multiple fields *NestedFields.
func (*NestedStruct) Attr ¶ added in v0.15.0
func (n *NestedStruct) Attr() *StructField
Attr returns nested struct related attribute field
func (*NestedStruct) Fields ¶
func (n *NestedStruct) Fields() map[string]*NestedField
Fields return nested fields for the given structure
func (*NestedStruct) StructField ¶
func (n *NestedStruct) StructField() *StructField
StructField returns nested struct fields related struct field
func (*NestedStruct) Type ¶
func (n *NestedStruct) Type() reflect.Type
Type returns nested struct's reflect.Type
type OrderedFieldset ¶ added in v0.15.0
type OrderedFieldset []*StructField
OrderedFieldset is the wrapper over the slice of struct fields that allows to keep the fields in an ordered sorting. The sorts is based on the fields index.
func (*OrderedFieldset) Insert ¶ added in v0.15.0
func (o *OrderedFieldset) Insert(field *StructField)
Insert inserts the field into an ordered fields slice. In order to insert the field a pointer to ordered fields must be used.
func (OrderedFieldset) Len ¶ added in v0.15.0
func (o OrderedFieldset) Len() int
Len implements sort.Interface interface.
func (OrderedFieldset) Less ¶ added in v0.15.0
func (o OrderedFieldset) Less(i, j int) bool
Less implements sort.Interface interface.
func (OrderedFieldset) Swap ¶ added in v0.15.0
func (o OrderedFieldset) Swap(i, j int)
Swap implements sort.Interface interface.
type RelationModelsLister ¶ added in v0.21.0
type RelationModelsLister interface {
ListRelationModels() []Model
}
RelationModelsLister is an interface that lists the model's unique relationship types.
type Relationship ¶
type Relationship struct {
// contains filtered or unexported fields
}
Relationship is the structure that contains the relation's required field's kind, join model (if exists) and the process option (onDelete, onUpdate) as well as the definition for the related model's type 'mStruct'.
func (*Relationship) ForeignKey ¶
func (r *Relationship) ForeignKey() *StructField
ForeignKey returns relationships foreign key.
func (*Relationship) IsManyToMany ¶ added in v0.15.0
func (r *Relationship) IsManyToMany() bool
IsManyToMany defines if the relationship is of many to many type.
func (*Relationship) IsToMany ¶ added in v0.15.0
func (r *Relationship) IsToMany() bool
IsToMany defines if the relationship is of to many kind.
func (*Relationship) IsToOne ¶ added in v0.15.0
func (r *Relationship) IsToOne() bool
IsToOne defines if the relationship is of to one type.
func (*Relationship) JoinModel ¶ added in v0.15.0
func (r *Relationship) JoinModel() *ModelStruct
JoinModel returns the join model for the given many2many relationship.
func (*Relationship) Kind ¶
func (r *Relationship) Kind() RelationshipKind
Kind returns relationship's kind.
func (*Relationship) ManyToManyForeignKey ¶ added in v0.15.0
func (r *Relationship) ManyToManyForeignKey() *StructField
ManyToManyForeignKey returns the foreign key of the many2many related model's.
func (*Relationship) RelatedModelStruct ¶ added in v0.16.0
func (r *Relationship) RelatedModelStruct() *ModelStruct
RelatedModelStruct returns relationship model *ModelStruct.
type RelationshipKind ¶
type RelationshipKind int
RelationshipKind is the enum used to define the Relationship's kind.
const ( // RelUnknown is the unknown default relationship kind. States for the relationship internal errors. RelUnknown RelationshipKind = iota // RelBelongsTo is the enum value for the 'Belongs To' relationship. // This relationship kind states that the model containing the relationship field // contains also the foreign key of the related models. // The foreign key is a related model's primary field. RelBelongsTo // RelHasOne is the enum value for the 'Has One' relationship. // This relationship kind states that the model is in a one to one relationship with // the related model. It also states that the foreign key is located in the related model. RelHasOne // RelHasMany is the enum value for the 'Has Many' relationship. // This relationship kind states that the model is in a many to one relationship with the // related model. It also states that the foreign key is located in the related model. RelHasMany // RelMany2Many is the enum value for the 'Many To Many' relationship. // This relationship kind states that the model is in a many to many relationship with the // related model. This relationship requires the usage of the join model structure that contains // foreign keys of both related model types. The 'Relationship' struct foreign key should relate to the // model where the related field is stored - i.e. model 'user' has relationship field 'pets' to the model 'pet' // then the relationship pets foreign key should be a 'user id'. In order to get the foreign key of the related model // the relationship has also a field 'MtmForeignKey' which should be a 'pet id'. RelMany2Many )
func (RelationshipKind) String ¶
func (r RelationshipKind) String() string
String implements fmt.Stringer interface.
type RepositoryNamer ¶ added in v0.15.0
type RepositoryNamer interface {
RepositoryName() string
}
RepositoryNamer is the interface used for the repositories to implement that defines it's name
type SingleRelationer ¶ added in v0.15.0
type SingleRelationer interface { // GetRelationModel gets the model for provided 'relation' field. It is used for the single relation models GetRelationModel(relation *StructField) (Model, error) // SetRelationModel sets the 'model' value in the 'relation' field. SetRelationModel(relation *StructField, model Model) error }
SingleRelationer is the interface used by the model with single relationship - HasOne or BelongsTo.
type StructField ¶
type StructField struct { Index []int // Database tags DatabaseName string DatabaseType string DatabaseUnknownTags []*FieldTag // contains filtered or unexported fields }
StructField represents a field structure with its json api parameters. and model relationships.
func (*StructField) BaseType ¶ added in v0.15.0
func (s *StructField) BaseType() reflect.Type
BaseType returns the base 'reflect.Type' for the provided field. The base is the lowest possible dereference of the field's type.
func (*StructField) CanBeSorted ¶ added in v0.15.0
func (s *StructField) CanBeSorted() bool
CanBeSorted returns if the struct field can be sorted.
func (*StructField) CodecISO8601 ¶ added in v0.19.0
func (s *StructField) CodecISO8601() bool
CodecISO8601 checks if it is a time field with ISO8601 formatting.
func (*StructField) CodecName ¶ added in v0.17.0
func (s *StructField) CodecName() string
CodecName gets the name of the field in the codec equivalent,
func (*StructField) CodecOmitEmpty ¶ added in v0.17.0
func (s *StructField) CodecOmitEmpty() bool
CodecOmitEmpty checks if the given field has a omitempty flag.
func (*StructField) CodecSkip ¶ added in v0.17.0
func (s *StructField) CodecSkip() bool
CodecSkip checks if the field is hidden for marshaling processes.
func (*StructField) DatabaseIndexes ¶ added in v0.17.0
func (s *StructField) DatabaseIndexes() []*DatabaseIndex
DatabaseIndexes gets the indexes where given field is being used.
func (*StructField) DatabaseNotNull ¶ added in v0.17.0
func (s *StructField) DatabaseNotNull() bool
DatabaseNotNull checks if the field is marked as database nullable.
func (*StructField) DatabaseSkip ¶ added in v0.17.0
func (s *StructField) DatabaseSkip() bool
DatabaseSkip checks if the field should be skipped in the database.
func (*StructField) DatabaseUnique ¶ added in v0.17.0
func (s *StructField) DatabaseUnique() bool
DatabaseUnique checks if the field is marked as database unique. It is not equivalent as unique index.
func (*StructField) ExtractCustomFieldTags ¶ added in v0.15.0
func (s *StructField) ExtractCustomFieldTags(fieldTag, tagSeparator, valuesSeparator string) []*FieldTag
ExtractCustomFieldTags extracts field tags from given struct field for provided 'fieldTag'. The tagSeparator and valuesSeparator are separator string value defined as follows:
type Model struct { Field string `fieldTag:"subtag=value1,value2;subtag2"` } ^ ^ ^ fieldTag valueSeparator tagSeparator
func (*StructField) ExtractFieldTags ¶ added in v0.1.4
func (s *StructField) ExtractFieldTags(fieldTag string) []*FieldTag
ExtractFieldTags extracts the []*mapping.FieldTag from the given *mapping.StructField for given StructField reflect tag.
func (*StructField) GetDereferencedType ¶ added in v0.15.0
func (s *StructField) GetDereferencedType() reflect.Type
GetDereferencedType returns structField dereferenced type.
func (*StructField) IsArray ¶ added in v0.15.0
func (s *StructField) IsArray() bool
IsArray checks if the field is an array.
func (*StructField) IsBasePtr ¶ added in v0.15.0
func (s *StructField) IsBasePtr() bool
IsBasePtr checks if the field has a pointer type in the base.
func (*StructField) IsCreatedAt ¶ added in v0.15.0
func (s *StructField) IsCreatedAt() bool
IsCreatedAt returns the boolean if the field is a 'CreatedAt' field.
func (*StructField) IsDeletedAt ¶ added in v0.15.0
func (s *StructField) IsDeletedAt() bool
IsDeletedAt returns the boolean if the field is a 'DeletedAt' field.
func (*StructField) IsField ¶ added in v0.15.0
func (s *StructField) IsField() bool
IsField checks if given struct field is a primary key, attribute or foreign key field.
func (*StructField) IsI18n ¶ added in v0.15.0
func (s *StructField) IsI18n() bool
IsI18n returns flag if the struct fields is an i18n.
func (*StructField) IsLanguage ¶ added in v0.15.0
func (s *StructField) IsLanguage() bool
IsLanguage checks if the field is a language type.
func (*StructField) IsMap ¶ added in v0.15.0
func (s *StructField) IsMap() bool
IsMap checks if the field is of map type.
func (*StructField) IsNestedField ¶ added in v0.15.0
func (s *StructField) IsNestedField() bool
IsNestedField checks if the field is not defined within ModelStruct.
func (*StructField) IsNestedStruct ¶ added in v0.15.0
func (s *StructField) IsNestedStruct() bool
IsNestedStruct checks if the field is a nested structure.
func (*StructField) IsNoFilter ¶ added in v0.15.0
func (s *StructField) IsNoFilter() bool
IsNoFilter checks whether the field uses no filter flag.
func (*StructField) IsPrimary ¶ added in v0.15.0
func (s *StructField) IsPrimary() bool
IsPrimary checks if the field is the primary field type.
func (*StructField) IsPtr ¶ added in v0.15.0
func (s *StructField) IsPtr() bool
IsPtr checks if the field is a pointer.
func (*StructField) IsRelationship ¶ added in v0.15.0
func (s *StructField) IsRelationship() bool
IsRelationship checks if given field is a relationship.
func (*StructField) IsSlice ¶ added in v0.15.0
func (s *StructField) IsSlice() bool
IsSlice checks if the field is a slice based.
func (*StructField) IsSortable ¶ added in v0.15.0
func (s *StructField) IsSortable() bool
IsSortable checks if the field has a sortable flag.
func (*StructField) IsTime ¶ added in v0.15.0
func (s *StructField) IsTime() bool
IsTime checks whether the field uses time flag.
func (*StructField) IsTimePointer ¶
func (s *StructField) IsTimePointer() bool
IsTimePointer checks if the field's type is a *time.time.
func (*StructField) IsUpdatedAt ¶ added in v0.15.0
func (s *StructField) IsUpdatedAt() bool
IsUpdatedAt returns the boolean if the field is a 'UpdatedAt' field.
func (*StructField) IsZeroValue ¶ added in v0.15.0
func (s *StructField) IsZeroValue(fieldValue interface{}) bool
IsZeroValue checks if the provided field has Zero value.
func (*StructField) Kind ¶ added in v0.15.0
func (s *StructField) Kind() FieldKind
Kind returns struct fields kind.
func (*StructField) ModelStruct ¶
func (s *StructField) ModelStruct() *ModelStruct
ModelStruct returns field's model struct.
func (*StructField) Nested ¶
func (s *StructField) Nested() *NestedStruct
Nested returns the nested structure.
func (*StructField) NeuronName ¶ added in v0.15.0
func (s *StructField) NeuronName() string
NeuronName returns the field's 'api' name.
func (*StructField) ReflectField ¶
func (s *StructField) ReflectField() reflect.StructField
ReflectField returns reflect.StructField related with this StructField.
func (*StructField) Relationship ¶
func (s *StructField) Relationship() *Relationship
Relationship returns relationship for provided field.
func (*StructField) Self ¶ added in v0.15.0
func (s *StructField) Self() *StructField
Self returns itself. Used in the nested fields. Implements structFielder interface.
func (*StructField) StoreDelete ¶
func (s *StructField) StoreDelete(key string)
StoreDelete deletes the store value at 'key'.
func (*StructField) StoreGet ¶
func (s *StructField) StoreGet(key string) (interface{}, bool)
StoreGet gets the value from the store at the key: 'key'..
func (*StructField) StoreSet ¶
func (s *StructField) StoreSet(key string, value interface{})
StoreSet sets into the store the value 'value' for given 'key'.
func (*StructField) String ¶ added in v0.15.0
func (s *StructField) String() string
String implements fmt.Stringer interface.
func (*StructField) Struct ¶ added in v0.15.0
func (s *StructField) Struct() *ModelStruct
Struct returns fields Model Structure.
type StructFieldValuer ¶ added in v0.21.0
type StructFieldValuer interface {
StructFieldValue(sField *StructField) (interface{}, error)
}
StructFieldValuer is an interface that gets the value for provided struct fields.
type ZeroChecker ¶ added in v0.15.0
type ZeroChecker interface { IsZero() bool GetZero() interface{} }
ZeroChecker is the interface that allows to check if the value is zero.