Documentation ¶
Index ¶
- func APIs(asts []*parser.AST) (res []*parser.APINode)
- func ActionSortableFieldNames(action *parser.ActionNode) ([]string, error)
- func AllHasManyRelationFields(asts []*parser.AST) []*parser.FieldNode
- func CompositeUniqueFields(model *parser.ModelNode, attribute *parser.AttributeNode) []*parser.FieldNode
- func Enum(asts []*parser.AST, name string) *parser.EnumNode
- func Enums(asts []*parser.AST) (res []*parser.EnumNode)
- func ExcludeBuiltInFields(f *parser.FieldNode) bool
- func ExcludeBuiltInModels(m *parser.ModelNode) bool
- func Field(model *parser.ModelNode, name string) *parser.FieldNode
- func FieldGetAttribute(field *parser.FieldNode, name string) *parser.AttributeNode
- func FieldHasAttribute(field *parser.FieldNode, name string) bool
- func FieldIsInCompositeUnique(model *parser.ModelNode, field *parser.FieldNode) bool
- func FieldIsUnique(field *parser.FieldNode) bool
- func FieldsInModelOfType(model *parser.ModelNode, requiredType string) []string
- func IsBelongsToModelField(asts []*parser.AST, model *parser.ModelNode, field *parser.FieldNode) bool
- func IsEnum(asts []*parser.AST, name string) bool
- func IsForeignKey(asts []*parser.AST, model *parser.ModelNode, field *parser.FieldNode) bool
- func IsHasManyModelField(asts []*parser.AST, field *parser.FieldNode) bool
- func IsHasOneModelField(asts []*parser.AST, field *parser.FieldNode) bool
- func IsIdentityModel(asts []*parser.AST, name string) bool
- func IsMessage(asts []*parser.AST, name string) bool
- func IsModel(asts []*parser.AST, name string) bool
- func IsUserDefinedType(asts []*parser.AST, name string) bool
- func Jobs(asts []*parser.AST) (ret []*parser.JobNode)
- func Message(asts []*parser.AST, name string) *parser.MessageNode
- func MessageNames(asts []*parser.AST) (ret []string)
- func Messages(asts []*parser.AST) (ret []*parser.MessageNode)
- func Model(asts []*parser.AST, name string) *parser.ModelNode
- func ModelActions(model *parser.ModelNode, filters ...ModelActionFilter) (res []*parser.ActionNode)
- func ModelAttributes(model *parser.ModelNode) (res []*parser.AttributeNode)
- func ModelCreateActions(model *parser.ModelNode, filters ...ModelActionFilter) (res []*parser.ActionNode)
- func ModelField(model *parser.ModelNode, name string) *parser.FieldNode
- func ModelFieldNames(model *parser.ModelNode) []string
- func ModelFields(model *parser.ModelNode, filters ...ModelFieldFilter) (res []*parser.FieldNode)
- func ModelFieldsOfType(model *parser.ModelNode, typeName string) []*parser.FieldNode
- func ModelNames(asts []*parser.AST, filters ...ModelFilter) (res []string)
- func Models(asts []*parser.AST, filters ...ModelFilter) (res []*parser.ModelNode)
- func PrimaryKey(modelName string, asts []*parser.AST) *parser.FieldNode
- func RelationAttributeValue(attr *parser.AttributeNode) (field string, ok bool)
- func ResolveInputField(asts []*parser.AST, input *parser.ActionInputNode, ...) (field *parser.FieldNode)
- func ResolveInputType(asts []*parser.AST, input *parser.ActionInputNode, ...) string
- func Roles(asts []*parser.AST) (res []*parser.RoleNode)
- func SubscriberNames(asts []*parser.AST) (res []string)
- func UserDefinedTypes(asts []*parser.AST) (res []string)
- func ValidOneToHasMany(belongsTo *parser.FieldNode, hasMany *parser.FieldNode) bool
- func ValidUniqueOneToHasOne(hasOne *parser.FieldNode, belongsTo *parser.FieldNode) bool
- type ModelActionFilter
- type ModelFieldFilter
- type ModelFilter
- type Relationship
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ActionSortableFieldNames ¶
func ActionSortableFieldNames(action *parser.ActionNode) ([]string, error)
ActionSortableFieldNames returns the field names of the @sortable attribute. If no @sortable attribute exists, an empty slice is returned.
func AllHasManyRelationFields ¶
AllHasManyRelationFields provides a list of all the fields in the schema which are of type Model and which are repeated.
func CompositeUniqueFields ¶ added in v0.370.0
func CompositeUniqueFields(model *parser.ModelNode, attribute *parser.AttributeNode) []*parser.FieldNode
CompositeUniqueFields returns the model's fields that make up a composite unique attribute
func ExcludeBuiltInFields ¶
func ExcludeBuiltInModels ¶
func FieldGetAttribute ¶
func FieldGetAttribute(field *parser.FieldNode, name string) *parser.AttributeNode
FieldGetAttribute returns the attribute of the given name on the given field, or nil, to signal that it doesn't have one.
func FieldIsInCompositeUnique ¶ added in v0.370.0
FieldIsInCompositeUnique returns true if a field is part of a composite unique attribute
func FieldIsUnique ¶
func FieldsInModelOfType ¶
FieldsInModelOfType provides a list of the field names for the fields in the given model, that have the given type name.
func IsBelongsToModelField ¶ added in v0.369.1
func IsBelongsToModelField(asts []*parser.AST, model *parser.ModelNode, field *parser.FieldNode) bool
IsBelongsToModelField returns true if the given field refers to a model in which this is in a 1:1 relationship and where the other model owns the relationship. This means the other model's field will have @unique defined and also the other model is where the foreign key will exist.
func IsForeignKey ¶
func IsHasManyModelField ¶
IsHasManyModelField returns true if the given field can be inferred to be a field that references another model, and is denoted as being REPEATED.
func IsHasOneModelField ¶
IsHasOneModelField returns true if the given field can be inferred to be a field that references another model, and is not denoted as being repeated.
func Message ¶
func Message(asts []*parser.AST, name string) *parser.MessageNode
Message finds the message in the schema of the given name. Or nil.
func MessageNames ¶
func ModelActions ¶
func ModelActions(model *parser.ModelNode, filters ...ModelActionFilter) (res []*parser.ActionNode)
func ModelAttributes ¶
func ModelAttributes(model *parser.ModelNode) (res []*parser.AttributeNode)
func ModelCreateActions ¶
func ModelCreateActions(model *parser.ModelNode, filters ...ModelActionFilter) (res []*parser.ActionNode)
ModelCreateActions returns all the actions in the given model, which are create-type actions.
func ModelFieldNames ¶
func ModelFields ¶
func ModelFields(model *parser.ModelNode, filters ...ModelFieldFilter) (res []*parser.FieldNode)
func ModelFieldsOfType ¶ added in v0.369.1
FieldsInModelOfType provides a list of the field names for the fields in the given model, that have the given type name.
func ModelNames ¶
func ModelNames(asts []*parser.AST, filters ...ModelFilter) (res []string)
func PrimaryKey ¶
PrimaryKey gives you the name of the primary key field on the given model. It favours fields that have the AttributePrimaryKey attribute, but drops back to the id field if none have.
func RelationAttributeValue ¶ added in v0.369.1
func RelationAttributeValue(attr *parser.AttributeNode) (field string, ok bool)
RelationAttributeValue attempts to retrieve the value of the @relation attribute
func ResolveInputField ¶
func ResolveInputField(asts []*parser.AST, input *parser.ActionInputNode, parentModel *parser.ModelNode) (field *parser.FieldNode)
ResolveInputField returns the field that the input's type references
func ResolveInputType ¶
func ResolveInputType(asts []*parser.AST, input *parser.ActionInputNode, parentModel *parser.ModelNode, action *parser.ActionNode) string
ResolveInputType returns a string represention of the type of the given input.
If the input is explicitly typed using a built in type that type is returned
example: (foo: Text) -> Text is returned
If `input` refers to a field on the parent model (or a nested field) then the type of that field is returned
example: (foo: some.field) -> The type of `field` on the model referrred to by `some` is returned
func SubscriberNames ¶ added in v0.368.0
SubscriberNames gets a unique slice of subscriber names which have been defined in the schema.
func UserDefinedTypes ¶
func ValidOneToHasMany ¶ added in v0.369.1
Determine if pair form a valid 1:M pattern where, for example:
belongsTo: author Author @relation(posts) hasMany: posts Post[]
Types ¶
type ModelActionFilter ¶
type ModelActionFilter func(a *parser.ActionNode) bool
type ModelFieldFilter ¶
type ModelFilter ¶
type Relationship ¶ added in v0.369.1
func GetRelationship ¶ added in v0.369.1
func GetRelationship(asts []*parser.AST, currentModel *parser.ModelNode, currentField *parser.FieldNode) (*Relationship, error)
GetRelationship will return the related model and field on that model which forms the relationship.
func GetRelationshipCandidates ¶ added in v0.369.1
func GetRelationshipCandidates(asts []*parser.AST, model *parser.ModelNode, field *parser.FieldNode) []*Relationship
GetRelationshipCandidates will find all the candidates relationships that can be formed with the related model. Each relationship field should only have exactly 1 candidate, otherwise there are incorrectly defined relationships in the schema.