Documentation
¶
Overview ¶
Package mapping contains neuron models mapped structures. It defines the models, fields (with options, kinds and types), relationships and field tags.
Index ¶
- 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 PrimaryValues(m *ModelStruct, value reflect.Value) (primaries []interface{}, err error)
- func StringValues(value interface{}, svalues *[]string) []string
- type ChangeStrategy
- type CollectionNamer
- type DeleteStrategy
- type ErrorStrategy
- type FieldKind
- type FieldTag
- type ModelMap
- func (m *ModelMap) Get(model reflect.Type) *ModelStruct
- func (m *ModelMap) GetByCollection(collection string) *ModelStruct
- func (m *ModelMap) GetModelStruct(model interface{}) (*ModelStruct, error)
- func (m *ModelMap) ModelByName(name string) *ModelStruct
- func (m *ModelMap) Models() []*ModelStruct
- func (m *ModelMap) RegisterModels(models ...interface{}) error
- func (m *ModelMap) Set(value *ModelStruct) 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) Config() *config.ModelConfig
- func (m *ModelStruct) CreatedAt() (*StructField, bool)
- func (m *ModelStruct) DeletedAt() (*StructField, bool)
- func (m *ModelStruct) Field(field string) (*StructField, bool)
- func (m *ModelStruct) FieldByName(name string) (*StructField, bool)
- func (m *ModelStruct) FieldCount() int
- func (m *ModelStruct) Fields() (fields []*StructField)
- func (m *ModelStruct) FilterKey(fk string) (*StructField, bool)
- func (m *ModelStruct) FilterKeys() (filterKeys []*StructField)
- func (m *ModelStruct) ForeignKey(fk string) (*StructField, bool)
- func (m *ModelStruct) ForeignKeys() (foreigns []*StructField)
- func (m *ModelStruct) HasForeignRelationships() bool
- func (m *ModelStruct) IsAfterCounter() bool
- func (m *ModelStruct) IsAfterLister() bool
- func (m *ModelStruct) IsBeforeCounter() bool
- func (m *ModelStruct) IsBeforeLister() bool
- func (m *ModelStruct) IsJoin() bool
- func (m *ModelStruct) LanguageField() *StructField
- func (m *ModelStruct) MaxIncludedCount() int
- func (m *ModelStruct) MaxIncludedDepth() int
- func (m *ModelStruct) NamerFunc() namer.Namer
- func (m *ModelStruct) Primary() *StructField
- func (m *ModelStruct) RelationField(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) StructFieldCount() int
- func (m *ModelStruct) StructFields() (fields []*StructField)
- func (m *ModelStruct) Type() reflect.Type
- func (m *ModelStruct) UpdatedAt() (*StructField, bool)
- func (m *ModelStruct) UseI18n() bool
- type NestedField
- type NestedStruct
- type NestedStructFielder
- type OptionsSetter
- type OrderedFields
- 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) OnCreate() *Strategy
- func (r *Relationship) OnDelete() *DeleteStrategy
- func (r *Relationship) OnPatch() *Strategy
- func (r *Relationship) Struct() *ModelStruct
- type RelationshipKind
- type RepositoryNamer
- type Strategy
- type StructField
- func (s *StructField) BaseType() reflect.Type
- func (s *StructField) CanBeSorted() bool
- func (s *StructField) ExtractCustomFieldTags(fieldTag, tagSeparator, valuesSeparator string) []*FieldTag
- func (s *StructField) ExtractFieldTags(fieldTag string) []*FieldTag
- func (s *StructField) FieldIndex() []int
- 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) IsHidden() bool
- func (s *StructField) IsI18n() bool
- func (s *StructField) IsISO8601() 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) IsOmitEmpty() 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
- func (s *StructField) ValueFromString(value string) (result interface{}, err error)
- type StructFielder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NestedStructFields ¶ added in v0.6.0
func NestedStructFields(n *NestedStruct) map[string]*NestedField
NestedStructFields gets the nested struct fields
func NestedStructMarshalType ¶ added in v0.6.0
func NestedStructMarshalType(n *NestedStruct) reflect.Type
NestedStructMarshalType returns the marshal type for the provided nested struct
func NestedStructSetMarshalType ¶ added in v0.6.0
func NestedStructSetMarshalType(n *NestedStruct, mType reflect.Type)
NestedStructSetMarshalType sets the nested structs marshal type
func NestedStructSetSubfield ¶ added in v0.6.0
func NestedStructSetSubfield(s *NestedStruct, n *NestedField)
NestedStructSetSubfield sets the subfield for the nestedStructr
func NestedStructType ¶ added in v0.6.0
func NestedStructType(n *NestedStruct) reflect.Type
NestedStructType returns the reflect.Type of the nestedStruct
func NewReflectValueMany ¶ added in v0.6.0
func NewReflectValueMany(m *ModelStruct) reflect.Value
NewReflectValueMany creates the *[]*m.Type reflect.Value.
func NewReflectValueSingle ¶ added in v0.6.0
func NewReflectValueSingle(m *ModelStruct) reflect.Value
NewReflectValueSingle creates and returns a model's new single value.
func NewValueMany ¶ added in v0.6.0
func NewValueMany(m *ModelStruct) interface{}
NewValueMany creates and returns a model's new slice of pointers to values.
func NewValueSingle ¶ added in v0.6.0
func NewValueSingle(m *ModelStruct) interface{}
NewValueSingle creates and returns new value for the given model type.
func PrimaryValues ¶ added in v0.6.0
func PrimaryValues(m *ModelStruct, value reflect.Value) (primaries []interface{}, err error)
PrimaryValues gets the primary values from the provided 'value' reflection. The reflection might be a slice or a single value. Returns the slice of interfaces containing primary field values.
func StringValues ¶ added in v0.8.2
StringValues gets the string values from the provided struct field, 'value'.
Types ¶
type ChangeStrategy ¶ added in v0.2.3
type ChangeStrategy int
ChangeStrategy defines the option on how to process the relationship.
const ( SetNull ChangeStrategy = iota NoAction Cascade Restrict )
Relationship options
type CollectionNamer ¶ added in v0.12.0
type CollectionNamer interface {
CollectionName() string
}
CollectionNamer is the interface used to get the collection name from the provided model.
type DeleteStrategy ¶ added in v0.6.0
type DeleteStrategy struct { Strategy OnChange ChangeStrategy }
DeleteStrategy is the strategy for the deletion options. The 'OnChange' varible defines how the relation should react on deletion of the root model.
type ErrorStrategy ¶ added in v0.6.0
type ErrorStrategy int
ErrorStrategy is the query strategy for given relationship field.
const ( Fail ErrorStrategy = iota Continue )
Relationship error strategies constant values, with the default set to 'fail'.
type FieldKind ¶
type FieldKind int
FieldKind is an enum that defines the following field type (i.e. 'primary', 'attribute').
const ( // UnknownType is the undefined field kind. UnknownType 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 // KindFilterKey is the field that is used only for special case filtering. KindFilterKey // KindNested is the field's type that is signed as Nested. KindNested )
type ModelMap ¶ added in v0.6.0
type ModelMap struct { Configs map[string]*config.ModelConfig DefaultRepository string NamerFunc namer.Namer // contains filtered or unexported fields }
ModelMap contains mapped models ( as reflect.Type ) to its ModelStruct representation.
func NewModelMap ¶ added in v0.6.0
func NewModelMap(namerFunc namer.Namer, c *config.Controller) *ModelMap
NewModelMap creates new model map with default 'namerFunc' and a controller config 'c'.
func (*ModelMap) Get ¶ added in v0.6.0
func (m *ModelMap) Get(model reflect.Type) *ModelStruct
Get gets the *ModelStruct for the provided 'model'.
func (*ModelMap) GetByCollection ¶ added in v0.6.0
func (m *ModelMap) GetByCollection(collection string) *ModelStruct
GetByCollection gets *ModelStruct by the 'collection'.
func (*ModelMap) GetModelStruct ¶ added in v0.6.0
func (m *ModelMap) GetModelStruct(model interface{}) (*ModelStruct, error)
GetModelStruct gets the model from the model map.
func (*ModelMap) ModelByName ¶ added in v0.6.0
func (m *ModelMap) ModelByName(name string) *ModelStruct
ModelByName gets the model by it's struct name.
func (*ModelMap) Models ¶ added in v0.6.0
func (m *ModelMap) Models() []*ModelStruct
Models returns all models set within given model map.
func (*ModelMap) RegisterModels ¶ added in v0.6.0
RegisterModels registers the model within the model map container.
func (*ModelMap) Set ¶ added in v0.6.0
func (m *ModelMap) Set(value *ModelStruct) error
Set sets the *ModelStruct for given map. If the model already exists the function returns an error.
type ModelStruct ¶
type ModelStruct struct {
// 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.5.1
func (m *ModelStruct) AllowClientID() bool
AllowClientID checks if the model allows client settable primary key values.
func (*ModelStruct) Attribute ¶ added in v0.6.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.8.2
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) Config ¶
func (m *ModelStruct) Config() *config.ModelConfig
Config gets the model's defined confgi.ModelConfig.
func (*ModelStruct) CreatedAt ¶ added in v0.7.0
func (m *ModelStruct) CreatedAt() (*StructField, bool)
CreatedAt gets the 'CreatedAt' field for the model struct.
func (*ModelStruct) DeletedAt ¶ added in v0.7.0
func (m *ModelStruct) DeletedAt() (*StructField, bool)
DeletedAt gets the 'DeletedAt' field for the model struct.
func (*ModelStruct) Field ¶ added in v0.8.2
func (m *ModelStruct) Field(field string) (*StructField, bool)
Field checks if the 'field' is an 'attribute', 'primary', 'foreign' or 'relationship' field.
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) FieldCount ¶ added in v0.6.0
func (m *ModelStruct) FieldCount() int
FieldCount gets the field number for given model.
func (*ModelStruct) Fields ¶
func (m *ModelStruct) Fields() (fields []*StructField)
Fields gets the model's primary, attribute, relationship and foreign key fields.
func (*ModelStruct) FilterKey ¶
func (m *ModelStruct) FilterKey(fk string) (*StructField, bool)
FilterKey return model's fitler key.
func (*ModelStruct) FilterKeys ¶ added in v0.8.2
func (m *ModelStruct) FilterKeys() (filterKeys []*StructField)
FilterKeys returns the slice of filter key fields.
func (*ModelStruct) ForeignKey ¶
func (m *ModelStruct) ForeignKey(fk string) (*StructField, 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.6.0
func (m *ModelStruct) ForeignKeys() (foreigns []*StructField)
ForeignKeys return ForeignKey Structfields for the given model.
func (*ModelStruct) HasForeignRelationships ¶ added in v0.6.0
func (m *ModelStruct) HasForeignRelationships() bool
HasForeignRelationships defines if the model has any foreign relationships (not a BelongsTo relationship).
func (*ModelStruct) IsAfterCounter ¶ added in v0.7.0
func (m *ModelStruct) IsAfterCounter() bool
IsAfterCounter checks if the model implements query.AfterCounter interface.
func (*ModelStruct) IsAfterLister ¶ added in v0.6.0
func (m *ModelStruct) IsAfterLister() bool
IsAfterLister defines if the model implements query.AfterLister interface.
func (*ModelStruct) IsBeforeCounter ¶ added in v0.7.0
func (m *ModelStruct) IsBeforeCounter() bool
IsBeforeCounter checks if the model implements query.AfterCounter interface.
func (*ModelStruct) IsBeforeLister ¶ added in v0.6.0
func (m *ModelStruct) IsBeforeLister() bool
IsBeforeLister defines if the model implements query.BeforeLister interface.
func (*ModelStruct) IsJoin ¶ added in v0.6.0
func (m *ModelStruct) IsJoin() bool
IsJoin defines if the model is a join table for the Many2Many relationship.
func (*ModelStruct) LanguageField ¶
func (m *ModelStruct) LanguageField() *StructField
LanguageField returns model's language field.
func (*ModelStruct) MaxIncludedCount ¶ added in v0.6.0
func (m *ModelStruct) MaxIncludedCount() int
MaxIncludedCount gets the maximum included field number for given model.
func (*ModelStruct) MaxIncludedDepth ¶ added in v0.3.0
func (m *ModelStruct) MaxIncludedDepth() int
MaxIncludedDepth gets the maximum included field depth for the queries.
func (*ModelStruct) NamerFunc ¶ added in v0.2.1
func (m *ModelStruct) NamerFunc() namer.Namer
NamerFunc returns namer func for the given Model.
func (*ModelStruct) Primary ¶
func (m *ModelStruct) Primary() *StructField
Primary returns model's primary field StructField.
func (*ModelStruct) RelationField ¶
func (m *ModelStruct) RelationField(field string) (*StructField, bool)
RelationField 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.5.1
func (m *ModelStruct) RelationFields() (relations []*StructField)
RelationFields gets all model's relationship fields.
func (*ModelStruct) SortScopeCount ¶ added in v0.6.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.6.0
func (m *ModelStruct) String() string
String implements fmt.Stringer interface.
func (*ModelStruct) StructFieldCount ¶ added in v0.8.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.7.0
func (m *ModelStruct) UpdatedAt() (*StructField, bool)
UpdatedAt gets the 'UpdatedAt' field for the model struct.
func (*ModelStruct) UseI18n ¶ added in v0.6.0
func (m *ModelStruct) UseI18n() bool
UseI18n returns the bool if the model struct uses i18n.
type NestedField ¶
type NestedField struct {
// contains filtered or unexported fields
}
NestedField is the field within the NestedStruct
func NestedStructSubField ¶ added in v0.6.0
func NestedStructSubField(n *NestedStruct, field string) (*NestedField, bool)
NestedStructSubField returns the NestedStruct subfield if exists.
func (*NestedField) NestedAttribute ¶ added in v0.6.0
func (n *NestedField) NestedAttribute() *StructField
NestedAttribute returns nested Fields Attribute
func (*NestedField) NestedFieldRoot ¶ added in v0.6.0
func (n *NestedField) NestedFieldRoot() *NestedStruct
NestedFieldRoot returns the root of the NestedField
func (*NestedField) Self ¶ added in v0.6.0
func (n *NestedField) Self() *StructField
Self is the relation to it's struct field.
func (*NestedField) SelfNested ¶ added in v0.6.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.6.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 structs related struct field
func (*NestedStruct) Type ¶
func (n *NestedStruct) Type() reflect.Type
Type returns nested struct's reflect.Type
type NestedStructFielder ¶ added in v0.6.0
type NestedStructFielder interface { StructFielder SelfNested() *NestedField }
NestedStructFielder is the interface used for nested struct fields.
type OptionsSetter ¶
type OptionsSetter interface {
SetOptions(field *StructField)
}
OptionsSetter is the interface used to set the options from the field's StructField. Used in models to prepare custom structures for the defined options.
type OrderedFields ¶ added in v0.8.1
type OrderedFields []*StructField
OrderedFields 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 (*OrderedFields) Insert ¶ added in v0.8.1
func (o *OrderedFields) 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 (OrderedFields) Len ¶ added in v0.8.1
func (o OrderedFields) Len() int
Len implements sort.Interface interface.
func (OrderedFields) Less ¶ added in v0.8.1
func (o OrderedFields) Less(i, j int) bool
Less implements sort.Interface interface.
func (OrderedFields) Swap ¶ added in v0.8.1
func (o OrderedFields) Swap(i, j int)
Swap implements sort.Interface interface.
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.6.0
func (r *Relationship) IsManyToMany() bool
IsManyToMany defines if the relationship is of many to many type.
func (*Relationship) IsToMany ¶ added in v0.6.0
func (r *Relationship) IsToMany() bool
IsToMany defines if the relationship is of to many kind.
func (*Relationship) IsToOne ¶ added in v0.6.0
func (r *Relationship) IsToOne() bool
IsToOne defines if the relationship is of to one type.
func (*Relationship) JoinModel ¶ added in v0.2.1
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.2.1
func (r *Relationship) ManyToManyForeignKey() *StructField
ManyToManyForeignKey returns the foreign key of the many2many related model's.
func (*Relationship) OnCreate ¶ added in v0.6.0
func (r *Relationship) OnCreate() *Strategy
OnCreate gets the on create strategy for the relationship.
func (*Relationship) OnDelete ¶ added in v0.6.0
func (r *Relationship) OnDelete() *DeleteStrategy
OnDelete gets the on delete strategy for the relationship.
func (*Relationship) OnPatch ¶ added in v0.6.0
func (r *Relationship) OnPatch() *Strategy
OnPatch gets the on create strategy for the relationship.
func (*Relationship) Struct ¶ added in v0.6.0
func (r *Relationship) Struct() *ModelStruct
Struct 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.6.0
type RepositoryNamer interface {
RepositoryName() string
}
RepositoryNamer is the interface used for the repositories to implement that defines it's name
type Strategy ¶ added in v0.6.0
type Strategy struct { QueryOrder uint OnError ErrorStrategy }
Strategy is the strategy for the relationship. It's 'QueryOrder' is the querying order for multiple strategies. It defines which strategies should be used firsts. The 'OnError' error strategy defines how the relation should react on the error occurrence while.
type StructField ¶
type StructField struct {
// contains filtered or unexported fields
}
StructField represents a field structure with its json api parameters. and model relationships.
func (*StructField) BaseType ¶ added in v0.6.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.6.0
func (s *StructField) CanBeSorted() bool
CanBeSorted returns if the struct field can be sorted.
func (*StructField) ExtractCustomFieldTags ¶ added in v0.13.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 tagSeparator valueSeparator
func (*StructField) ExtractFieldTags ¶ added in v0.2.1
func (s *StructField) ExtractFieldTags(fieldTag string) []*FieldTag
ExtractFieldTags extracts the []*mapping.FieldTag from the given *mapping.StructField for given StructField reflect tag.
func (*StructField) FieldIndex ¶
func (s *StructField) FieldIndex() []int
FieldIndex gets the field's index.
func (*StructField) GetDereferencedType ¶ added in v0.6.0
func (s *StructField) GetDereferencedType() reflect.Type
GetDereferencedType returns structField dereferenced type.
func (*StructField) IsArray ¶ added in v0.6.0
func (s *StructField) IsArray() bool
IsArray checks if the field is an array.
func (*StructField) IsBasePtr ¶ added in v0.6.0
func (s *StructField) IsBasePtr() bool
IsBasePtr checks if the field has a pointer type in the base.
func (*StructField) IsCreatedAt ¶ added in v0.7.0
func (s *StructField) IsCreatedAt() bool
IsCreatedAt returns the boolean if the field is a 'CreatedAt' field.
func (*StructField) IsDeletedAt ¶ added in v0.7.0
func (s *StructField) IsDeletedAt() bool
IsDeletedAt returns the boolean if the field is a 'DeletedAt' field.
func (*StructField) IsHidden ¶ added in v0.6.0
func (s *StructField) IsHidden() bool
IsHidden checks if the field is hidden for marshaling processes.
func (*StructField) IsI18n ¶ added in v0.6.0
func (s *StructField) IsI18n() bool
IsI18n returns flag if the struct fields is an i18n.
func (*StructField) IsISO8601 ¶ added in v0.6.0
func (s *StructField) IsISO8601() bool
IsISO8601 checks if it is a time field with ISO8601 formatting.
func (*StructField) IsLanguage ¶ added in v0.6.0
func (s *StructField) IsLanguage() bool
IsLanguage checks if the field is a language type.
func (*StructField) IsMap ¶ added in v0.6.0
func (s *StructField) IsMap() bool
IsMap checks if the field is of map type.
func (*StructField) IsNestedField ¶ added in v0.6.0
func (s *StructField) IsNestedField() bool
IsNestedField checks if the field is not defined within ModelStruct.
func (*StructField) IsNestedStruct ¶ added in v0.6.0
func (s *StructField) IsNestedStruct() bool
IsNestedStruct checks if the field is a nested structure.
func (*StructField) IsNoFilter ¶ added in v0.6.0
func (s *StructField) IsNoFilter() bool
IsNoFilter checks wether the field uses no filter flag.
func (*StructField) IsOmitEmpty ¶ added in v0.6.0
func (s *StructField) IsOmitEmpty() bool
IsOmitEmpty checks if the given field has a omitempty flag.
func (*StructField) IsPrimary ¶ added in v0.6.0
func (s *StructField) IsPrimary() bool
IsPrimary checks if the field is the primary field type.
func (*StructField) IsPtr ¶ added in v0.6.0
func (s *StructField) IsPtr() bool
IsPtr checks if the field is a pointer.
func (*StructField) IsRelationship ¶ added in v0.6.0
func (s *StructField) IsRelationship() bool
IsRelationship checks if given field is a relationship.
func (*StructField) IsSlice ¶ added in v0.6.0
func (s *StructField) IsSlice() bool
IsSlice checks if the field is a slice based.
func (*StructField) IsSortable ¶ added in v0.6.0
func (s *StructField) IsSortable() bool
IsSortable checks if the field has a sortable flag.
func (*StructField) IsTime ¶ added in v0.6.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.7.0
func (s *StructField) IsUpdatedAt() bool
IsUpdatedAt returns the boolean if the field is a 'UpdatedAt' field.
func (*StructField) IsZeroValue ¶ added in v0.6.0
func (s *StructField) IsZeroValue(fieldValue interface{}) bool
IsZeroValue checks if the provided field has Zero value.
func (*StructField) Kind ¶ added in v0.8.2
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.2.1
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.6.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.5.1
func (s *StructField) String() string
String implements fmt.Stringer interface.
func (*StructField) Struct ¶ added in v0.6.0
func (s *StructField) Struct() *ModelStruct
Struct returns fields Model Structure.
func (*StructField) TagValues ¶ added in v0.6.0
func (s *StructField) TagValues(tag string) url.Values
TagValues returns the url.Values for the specific tag.
func (*StructField) ValueFromString ¶ added in v0.5.1
func (s *StructField) ValueFromString(value string) (result interface{}, err error)
ValueFromString gets the field value from the provided 'value' string.
type StructFielder ¶ added in v0.6.0
type StructFielder interface {
Self() *StructField
}
StructFielder is the interfaces used for getting the pointer to itself