mapping

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeStrategy added in v0.2.3

type ChangeStrategy models.ChangeStrategy

ChangeStrategy is the relationship field's option enum.

const (
	// Restrict is a restrict relationship option.
	Restrict ChangeStrategy = iota
	NoAction
	Cascade
	SetNull
)

ChangeStrategies are used to define the default behaviour of the model's deleting processes.

type FieldKind

type FieldKind models.FieldKind

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
)

func (FieldKind) String

func (f FieldKind) String() string

String implements fmt.Stringer interface.

type FieldTag added in v0.2.1

type FieldTag struct {
	Key    string
	Values []string
}

FieldTag is the key: values pair for the given field struct's tag.

type ModelStruct

type ModelStruct models.ModelStruct

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) Attr

func (m *ModelStruct) Attr(attr string) (*StructField, bool)

Attr returns the attribute for the provided ModelStruct. If the attribute doesn't exists returns nil field and false.

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) FieldByName

func (m *ModelStruct) FieldByName(name string) (*StructField, bool)

FieldByName gets the StructField by the 'name' argument. The 'name' may be a StructField's Name or NeuronName.

func (*ModelStruct) Fields

func (m *ModelStruct) Fields() (fields []*StructField)

Fields gets all attributes and relationships StructFields for the Model.

func (*ModelStruct) FilterKey

func (m *ModelStruct) FilterKey(fk string) (*StructField, bool)

FilterKey checks and returns model's filter key. The 'fk' filter key field name may be a Neuron name or Golang StructField name.

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) LanguageField

func (m *ModelStruct) LanguageField() *StructField

LanguageField returns model's language field.

func (*ModelStruct) MaxIncludedDepth added in v0.3.0

func (m *ModelStruct) MaxIncludedDepth() int

MaxIncludedDepth gets maximum number of included nested depth.

func (*ModelStruct) NamerFunc added in v0.2.1

func (m *ModelStruct) NamerFunc() namer.Namer

NamerFunc returns the namer func used by 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(rel 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() []*StructField

RelationFields gets all model's relationship 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) StructFields

func (m *ModelStruct) StructFields() (mFields []*StructField)

StructFields return all struct fields mapping used by the model.

func (*ModelStruct) Type

func (m *ModelStruct) Type() reflect.Type

Type returns model's reflect.Type.

type NestedField

type NestedField models.NestedField

NestedField is the nested field within the NestedStruct.

func (*NestedField) StoreGet

func (s *NestedField) StoreGet(key string) (interface{}, bool)

StoreGet gets the value from the store at the key: 'key'.

func (*NestedField) StoreSet

func (s *NestedField) StoreSet(key string, value interface{})

StoreSet sets into the store the value 'value' for given 'key'.

func (*NestedField) StructField

func (s *NestedField) StructField() *StructField

StructField gets the structField for provided NestedFieldvalue.

type NestedStruct

type NestedStruct models.NestedStruct

NestedStruct is the structure that represtents nested attribute structure.

func (*NestedStruct) Attribute

func (s *NestedStruct) Attribute() *StructField

Attribute returns the attribute on the level of the 'ModelStruct' fields.

func (*NestedStruct) Fields

func (s *NestedStruct) Fields() []*NestedField

Fields returns all nested fields within the nested struct.

func (*NestedStruct) StoreGet

func (s *NestedStruct) StoreGet(key string) (interface{}, bool)

StoreGet gets the value from the store at the key: 'key'.

func (*NestedStruct) StoreSet

func (s *NestedStruct) StoreSet(key string, value interface{})

StoreSet sets into the store the value 'value' for given 'key'.

func (*NestedStruct) StructField

func (s *NestedStruct) StructField() *StructField

StructField returns the struct field related with the nested struct. It differs from the Attribute method. The StructField method returns StructField on any level where the nested structure is defined.

func (*NestedStruct) Type

func (s *NestedStruct) Type() reflect.Type

Type returns the reflect.Type of the model within the nested struct.

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 Relationship

type Relationship models.Relationship

Relationship is a structure that defines the relation field's relationship.

func (*Relationship) ForeignKey

func (r *Relationship) ForeignKey() *StructField

ForeignKey returns foreign key for given relationship.

func (*Relationship) JoinModel added in v0.2.1

func (r *Relationship) JoinModel() *ModelStruct

JoinModel is the join model used for the many2many relationship.

func (*Relationship) Kind

func (r *Relationship) Kind() RelationshipKind

Kind returns relationship 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) ModelStruct

func (r *Relationship) ModelStruct() *ModelStruct

ModelStruct returns relationships model struct - related model structure.

type RelationshipKind

type RelationshipKind models.RelationshipKind

RelationshipKind is the relation field's relationship kind enum.

const (
	// RelUnknown unknown relationship kind.
	RelUnknown RelationshipKind = iota
	// RelBelongsTo 'belongs to' relationship kind.
	RelBelongsTo
	// RelHasOne 'has one' relationship kind.
	RelHasOne
	// RelHasMany 'has many' relationship kind.
	RelHasMany
	// RelMany2Many 'many 2 many' relationship kind.
	RelMany2Many
)

func (RelationshipKind) String

func (r RelationshipKind) String() string

String implements fmt.Stringer interface.

type StructField

type StructField models.StructField

StructField represents a field structure with its json api parameters. and model relationships.

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) FieldKind

func (s *StructField) FieldKind() FieldKind

FieldKind returns struct fields kind.

func (*StructField) IsTimePointer

func (s *StructField) IsTimePointer() bool

IsTimePointer checks if the field's type is a *time.time.

func (*StructField) ModelStruct

func (s *StructField) ModelStruct() *ModelStruct

ModelStruct returns field's model struct.

func (*StructField) Name

func (s *StructField) Name() string

Name returns field's 'golang' name.

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) 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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL