Documentation
¶
Overview ¶
Package tqlgen provides tools for parsing TypeQL schemas and generating Go code from them.
Package tqlgen provides utilities for transforming TypeDB names into Go-idiomatic names.
Package tqlgen provides code generation from TypeQL schemas.
Index ¶
- Variables
- func ExtractAnnotations(input string) map[string]map[string]string
- func Render(w io.Writer, schema *ParsedSchema, cfg RenderConfig) error
- func RenderDTO(w io.Writer, data *DTOData) error
- func RenderLeafConstants(w io.Writer, schema *ParsedSchema, cfg LeafConstantsConfig) error
- func RenderRegistry(w io.Writer, data *RegistryData) error
- func ToPascalCase(name string) string
- func ToPascalCaseAcronyms(name string) string
- func ToSnakeCase(name string) string
- type Annotation
- type AsClause
- type AttrDef
- type AttributeSpec
- type BaseStructConfig
- type CardAnnot
- type CompositeEntityConfig
- type DTOConfig
- type DTOData
- type DocAnnot
- type EntityClause
- type EntityDef
- type EntityFieldOverride
- type EntitySpec
- type EnumCtx
- type EnumValueCtx
- type FunBodyTok
- type FunDef
- type FunctionSpec
- type JSONSchemaCtx
- type JSONSchemaPropCtx
- type KVCtx
- type KVMapCtx
- type KVSliceCtx
- type LeafConstantsConfig
- type MetaAnnot
- type MetaSpec
- type OwnsDef
- type OwnsSpec
- type ParameterSpec
- type ParsedSchema
- type PlaysDef
- type PlaysSpec
- type RangeAnnot
- type RangeTok
- type RegexAnnot
- type RegistryConfig
- type RegistryData
- type RelSchemaCtx
- type RelatesDef
- type RelatesSpec
- type RelationClause
- type RelationDef
- type RelationSpec
- type RenderConfig
- type RoleCtx
- type SimpleDef
- type StructDefP
- type StructFieldP
- type StructFieldSpec
- type StructSpec
- type SubClause
- type SubkeyAnnot
- type TQLFileSimple
- type TypeConstCtx
- type ValuesAnnot
Constants ¶
This section is empty.
Variables ¶
var CommonAcronyms = map[string]string{
"id": "ID",
"url": "URL",
"uuid": "UUID",
"api": "API",
"http": "HTTP",
"iid": "IID",
"nf": "NF",
}
CommonAcronyms defines a set of common abbreviations that should be fully uppercased when generating Go names.
Functions ¶
func ExtractAnnotations ¶
ExtractAnnotations parses comment annotations of the form "# @key value" from schema text. Returns a map of type name -> annotation map.
func Render ¶
func Render(w io.Writer, schema *ParsedSchema, cfg RenderConfig) error
Render processes a ParsedSchema and writes the generated Go source code, gofmt-formatted, to the provided writer. It returns an error when two schema labels would fold to the same Go identifier (e.g. "user-name" and "user_name"), since the generated code would not compile, and when the rendered output is not valid Go (the raw output is still written so it can be inspected). Non-fatal issues (unknown value types, undefined attributes, roles with no resolvable player, skipped functions) are reported to cfg.WarnWriter (os.Stderr by default).
func RenderDTO ¶ added in v1.3.0
RenderDTO writes a gofmt-formatted DTO Go file from DTOData. It returns an error when data.PackageName is empty (the generated file would not be valid Go) or when the rendered output fails to format.
func RenderLeafConstants ¶ added in v1.3.0
func RenderLeafConstants(w io.Writer, schema *ParsedSchema, cfg LeafConstantsConfig) error
RenderLeafConstants writes a standalone, gofmt-formatted leaf package containing only type, relation, and enum constants. This package has zero internal dependencies, making it safe to import from any package. It returns an error when cfg.PackageName is empty.
func RenderRegistry ¶ added in v1.2.0
func RenderRegistry(w io.Writer, data *RegistryData) error
RenderRegistry writes a complete, gofmt-formatted schema registry Go file from RegistryData. It returns an error when data.PackageName is empty (the generated file would not be valid Go) or when the rendered output fails to format.
func ToPascalCase ¶
ToPascalCase transforms a kebab-case or snake_case string into PascalCase.
func ToPascalCaseAcronyms ¶
ToPascalCaseAcronyms transforms a string into PascalCase while preserving the casing of common Go acronyms.
func ToSnakeCase ¶
ToSnakeCase transforms a kebab-case string into snake_case.
Types ¶
type Annotation ¶
type Annotation struct {
Key bool `parser:" @'@key'"`
Unique bool `parser:"| @'@unique'"`
Abstract bool `parser:"| @'@abstract'"`
Cascade bool `parser:"| @'@cascade'"`
Independent bool `parser:"| @'@independent'"`
Distinct bool `parser:"| @'@distinct'"`
Card *CardAnnot `parser:"| @@"`
Regex *RegexAnnot `parser:"| @@"`
Values *ValuesAnnot `parser:"| @@"`
Range *RangeAnnot `parser:"| @@"`
Subkey *SubkeyAnnot `parser:"| @@"`
Doc *DocAnnot `parser:"| @@"`
Meta *MetaAnnot `parser:"| @@"`
}
Annotation parses TypeQL schema annotations. Some annotations are carried into generated Go metadata, while doc/meta/capability annotations are accepted for parser compatibility and otherwise ignored.
type AsClause ¶
type AsClause struct {
Parent string `parser:"'as' @Ident"`
}
AsClause parses: as parent-role
type AttrDef ¶
type AttrDef struct {
Name string `parser:"'attribute' @Ident"`
Parent *SubClause `parser:"@@?"`
PreAnnots []Annotation `parser:"@@*"`
Comma string `parser:"','?"`
ValueType string `parser:"('value' @Ident)?"`
Annots []Annotation `parser:"@@*"`
Semi string `parser:"';'"`
}
AttrDef parses: attribute name [sub parent] [annotations] [,] [value type] [@constraint(...)]; The value clause is optional: abstract attribute supertypes omit it, and subtyped attributes inherit it from their parent chain (resolved in convertAST).
type AttributeSpec ¶
type AttributeSpec struct {
// Name is the name of the attribute type.
Name string
// ValueType is the base value type of the attribute (string, integer, double, boolean, datetime).
ValueType string
// Doc is the optional @doc annotation text.
Doc string
// Meta is the list of @meta annotations.
Meta []MetaSpec
// Regex is an optional regular expression constraint for the attribute values.
Regex string
// Values is an optional list of allowed values (enumeration constraint).
Values []string
// RangeOp is an optional range constraint (e.g., "1..5").
RangeOp string
// Parent is the parent attribute type name when the attribute is declared
// with `sub` (attribute subtyping). Empty for root attributes.
Parent string
// Abstract indicates whether the attribute type is declared @abstract.
Abstract bool
}
AttributeSpec describes a TypeQL attribute definition.
type BaseStructConfig ¶ added in v1.3.0
type BaseStructConfig struct {
// SourceEntity is the schema entity name that triggers this base struct.
SourceEntity string
// BaseName is the Go struct name prefix (e.g., "BaseArtifact").
BaseName string
// InheritedAttrs lists attribute names defined in the base struct.
// These are skipped when rendering child entity DTOs.
InheritedAttrs []string
// ExtraFields adds additional fields as name → Go type annotation.
ExtraFields map[string]string
}
BaseStructConfig configures a shared embedded base struct for an entity hierarchy. When an entity inherits from SourceEntity, its DTOs embed the base struct instead of repeating the inherited fields.
type CardAnnot ¶
type CardAnnot struct {
Expr string `parser:"'@card' '(' @CardExpr ')'"`
}
CardAnnot parses: @card(expr)
type CompositeEntityConfig ¶ added in v1.3.0
type CompositeEntityConfig struct {
// Name is the Go struct name for the composite DTO (e.g., "ArtifactDTO").
Name string
// Entities lists the TypeDB entity names to merge.
Entities []string
// TypeName is the TypeDB type name for TypeName() method (e.g., "artifact").
TypeName string
}
CompositeEntityConfig merges multiple entity subtypes into a single flat DTO with a Type discriminator. Useful for polymorphic API endpoints.
type DTOConfig ¶ added in v1.3.0
type DTOConfig struct {
// PackageName is the Go package name for the generated file (required).
PackageName string
// UseAcronyms applies Go acronym naming conventions (e.g., "ID" not "Id").
UseAcronyms bool
// SkipAbstract excludes abstract types from DTO generation.
SkipAbstract bool
// IDFieldName is the name of the ID field in Out structs (default "ID").
IDFieldName string
// StrictOut makes required fields non-pointer in Out structs.
// When false (default), all attribute fields in Out are pointers for safety.
StrictOut bool
// ExcludeEntities lists entity names to skip during generation.
ExcludeEntities []string
// ExcludeRelations lists relation names to skip during generation.
ExcludeRelations []string
// SkipRelationOut skips generating Out structs for relations.
SkipRelationOut bool
// BaseStructs configures shared base structs for entity hierarchies.
BaseStructs []BaseStructConfig
// EntityFieldOverrides provides per-entity, per-variant field overrides.
EntityFieldOverrides []EntityFieldOverride
// CompositeEntities configures merged flat structs from multiple entity types.
CompositeEntities []CompositeEntityConfig
// EntityOutName overrides the interface name for entity Out DTOs (default "EntityOut").
EntityOutName string
// EntityCreateName overrides the interface name for entity Create DTOs (default "EntityCreate").
EntityCreateName string
// EntityPatchName overrides the interface name for entity Patch DTOs (default "EntityPatch").
EntityPatchName string
// RelationOutName overrides the interface name for relation Out DTOs (default "RelationOut").
RelationOutName string
// RelationCreateName overrides the interface name for relation Create DTOs (default "RelationCreate").
RelationCreateName string
// RelationCreateEmbed is a struct name to embed in all relation Create DTOs.
RelationCreateEmbed string
}
DTOConfig configures DTO (Data Transfer Object) code generation. DTOs generate Out/Create/Patch struct variants for HTTP API layers.
type DTOData ¶ added in v1.3.0
type DTOData struct {
PackageName string
NeedsTime bool
IDFieldName string
// Base structs (from BaseStructConfig)
BaseStructs []baseStructDTOCtx
// Entity DTOs
Entities []entityDTOCtx
// Relation DTOs
Relations []relationDTOCtx
SkipRelationOut bool
RelationCreateEmbed string
// Composite entity DTOs
Composites []compositeDTOCtx
// Union interface lists (concrete types only)
ConcreteEntities []string // Go type names
ConcreteRelations []string
// Configurable interface names
EntityOutName string
EntityCreateName string
EntityPatchName string
RelationOutName string
RelationCreateName string
}
DTOData holds all schema-derived data for DTO code generation.
func BuildDTOData ¶ added in v1.3.0
func BuildDTOData(schema *ParsedSchema, cfg DTOConfig) *DTOData
BuildDTOData populates DTOData from a parsed schema. The schema should have AccumulateInheritance() called before this. PackageName is required to render the result: RenderDTO returns an error when it is empty.
type DocAnnot ¶ added in v1.12.0
type DocAnnot struct {
Text string `parser:"'@doc' '(' @String ')'"`
}
DocAnnot parses: @doc("docstring")
type EntityClause ¶
type EntityClause struct {
Owns *OwnsDef `parser:" @@"`
Plays *PlaysDef `parser:"| @@"`
Sub *SubClause `parser:"| @@"`
}
EntityClause is one of: owns, plays, or sub. The comma-constraint sub form (`entity x @abstract, sub y`) is how generators emit annotated subtypes, since annotations after an inline `sub` bind to the sub clause (ANN9).
type EntityDef ¶
type EntityDef struct {
Name string `parser:"'entity' @Ident"`
Parent *SubClause `parser:"@@?"`
Annots []Annotation `parser:"@@*"`
Comma string `parser:"','?"`
Clauses []EntityClause `parser:"( @@ ( ',' @@ )* )? ';'"`
}
EntityDef parses: entity name [sub parent] [annotations] [, clause...];
type EntityFieldOverride ¶ added in v1.3.0
type EntityFieldOverride struct {
// Entity is the TypeDB entity name.
Entity string
// Field is the TypeDB attribute name.
Field string
// Variant is the DTO variant: "out", "create", or "patch".
Variant string
// Required overrides whether the field is required (non-pointer).
// nil means keep the schema default.
Required *bool
}
EntityFieldOverride provides per-entity, per-variant field overrides.
type EntitySpec ¶
type EntitySpec struct {
// Name is the name of the entity type.
Name string
// Parent is the name of the parent entity type if this is a subtype.
Parent string
// Abstract indicates whether the entity type is defined as abstract.
Abstract bool
// Doc is the optional @doc annotation text.
Doc string
// Meta is the list of @meta annotations.
Meta []MetaSpec
// Owns is a list of attributes owned by this entity type.
Owns []OwnsSpec
// Plays is a list of relation roles this entity type can play.
Plays []PlaysSpec
}
EntitySpec describes a TypeQL entity definition.
type EnumCtx ¶ added in v1.2.0
type EnumCtx = enumCtx
EnumCtx holds enum constants derived from @values constraints.
type EnumValueCtx ¶ added in v1.2.0
type EnumValueCtx = enumValueCtx
EnumValueCtx holds a single enum constant.
type FunBodyTok ¶
type FunBodyTok struct {
Tok string `` /* 141-byte string literal not displayed */
}
FunBodyTok matches any token except the keywords that open a new top-level definition (or another fun), so the parser exits the function body at the next definition instead of swallowing the rest of the file. Limitation: a function body using one of these words as a bare label (e.g. `$t sub entity`) ends the body early at that word.
type FunDef ¶
type FunDef struct {
Name string `parser:"'fun' @Ident"`
Body []FunBodyTok `parser:"@@*"`
}
FunDef parses: fun name <body tokens until the next top-level definition or EOF> The body is captured as a flat list of tokens for signature extraction.
type FunctionSpec ¶
type FunctionSpec struct {
// Name is the name of the function.
Name string
// Parameters is a list of parameters accepted by the function.
Parameters []ParameterSpec
// ReturnType is the TypeQL return type of the function.
ReturnType string
// Doc is the optional @doc annotation text.
Doc string
// Meta is the list of @meta annotations.
Meta []MetaSpec
}
FunctionSpec describes the signature of a TypeQL function definition.
type JSONSchemaCtx ¶ added in v1.3.0
type JSONSchemaCtx struct {
TypeName string
Properties []JSONSchemaPropCtx
Required []string
}
JSONSchemaCtx holds a JSON schema fragment for a single type.
type JSONSchemaPropCtx ¶ added in v1.3.0
JSONSchemaPropCtx describes a single property in a JSON schema fragment.
type KVCtx ¶ added in v1.2.0
type KVCtx struct {
Key, Value string
}
KVCtx is a simple key-value pair.
type KVMapCtx ¶ added in v1.3.0
KVMapCtx is a key with a map of string key-value pairs (for annotations).
type KVSliceCtx ¶ added in v1.2.0
KVSliceCtx is a key with multiple string values.
type LeafConstantsConfig ¶ added in v1.3.0
type LeafConstantsConfig struct {
// PackageName for the generated file (e.g. "schema").
PackageName string
// UseAcronyms applies Go acronym naming conventions.
UseAcronyms bool
// SkipAbstract excludes abstract types.
SkipAbstract bool
}
LeafConstantsConfig configures leaf constants package generation.
type MetaAnnot ¶ added in v1.12.0
type MetaAnnot struct {
Key string `parser:"'@meta' '(' @String ','"`
Value string `parser:"@String ')'"`
}
MetaAnnot parses: @meta("key", "value")
type MetaSpec ¶ added in v1.12.0
type MetaSpec struct {
// Key is the metadata key.
Key string
// Value is the metadata value.
Value string
}
MetaSpec describes a TypeDB @meta("key", "value") annotation.
type OwnsDef ¶
type OwnsDef struct {
Attribute string `parser:"'owns' @Ident"`
IsList bool `parser:"( @'[' ']' )?"`
Annots []Annotation `parser:"@@*"`
}
OwnsDef parses: owns attr-name[[]] [@key] [@unique] [@card(...)] The optional '[]' suffix marks a TypeQL 3.x ordered-list ownership.
type OwnsSpec ¶
type OwnsSpec struct {
// Attribute is the name of the attribute type being owned.
Attribute string
// Key indicates whether this attribute is a key for the owner.
Key bool
// Unique indicates whether the attribute value must be unique across all instances.
Unique bool
// Card specifies the cardinality of the ownership (e.g., "0..1", "1..5").
Card string
// IsList indicates a TypeQL 3.x ordered-list ownership (owns attr[]).
IsList bool
// Doc is the optional @doc annotation text.
Doc string
// Meta is the list of @meta annotations.
Meta []MetaSpec
}
OwnsSpec describes an "owns attribute" clause in an entity or relation definition.
type ParameterSpec ¶
type ParameterSpec struct {
// Name is the name of the parameter (without the '$' prefix).
Name string
// TypeName is the TypeQL type name expected for this parameter.
TypeName string
}
ParameterSpec describes a single parameter of a TypeQL function.
type ParsedSchema ¶
type ParsedSchema struct {
// Attributes is a list of all attribute definitions in the schema.
Attributes []AttributeSpec
// Entities is a list of all entity definitions in the schema.
Entities []EntitySpec
// Relations is a list of all relation definitions in the schema.
Relations []RelationSpec
// Functions is a list of all function signatures in the schema.
Functions []FunctionSpec
// Structs is a list of all struct definitions in the schema.
Structs []StructSpec
}
ParsedSchema holds all components extracted from a TypeQL schema file, including attribute, entity, and relation definitions, as well as functions and structs.
func ParseSchema ¶
func ParseSchema(input string) (*ParsedSchema, error)
ParseSchema parses a TypeQL schema string into a ParsedSchema structure. It handles attribute, entity, relation, function, and struct definitions. Function blocks are parsed by the grammar natively — no pre-processing needed.
func ParseSchemaFile ¶
func ParseSchemaFile(path string) (*ParsedSchema, error)
ParseSchemaFile reads a TypeQL schema from the specified file path and parses it.
func (*ParsedSchema) AccumulateInheritance ¶
func (s *ParsedSchema) AccumulateInheritance() error
AccumulateInheritance propagates owns/plays from parent entities/relations to their children, so each child has the complete set of fields. It returns an error when the schema declares an inheritance cycle (e.g. `a sub b` and `b sub a`), which would otherwise recurse forever. Types whose parent is not defined in the schema are left as-is.
type PlaysDef ¶
type PlaysDef struct {
Relation string `parser:"'plays' @Ident"`
Role string `parser:"':' @Ident"`
Annots []Annotation `parser:"@@*"`
}
PlaysDef parses: plays relation:role
type PlaysSpec ¶
type PlaysSpec struct {
// Relation is the name of the relation type.
Relation string
// Role is the name of the role played by the owner within that relation.
Role string
// Doc is the optional @doc annotation text.
Doc string
// Meta is the list of @meta annotations.
Meta []MetaSpec
}
PlaysSpec describes a "plays relation:role" clause.
type RangeAnnot ¶
type RangeAnnot struct {
Toks []RangeTok `parser:"'@range' '(' @@+ ')'"`
}
RangeAnnot parses: @range(operand), where the operand is any TypeQL range expression — integer (1..5), decimal (0.5..9.5), date/datetime, or string ("a".."z") bounds, including half-open forms. The operand is captured as a flat token list up to the closing parenthesis and reassembled verbatim by Expr.
func (*RangeAnnot) Expr ¶
func (r *RangeAnnot) Expr() string
Expr returns the range operand reassembled from its tokens. TypeQL range operands contain no significant whitespace, so plain concatenation reconstructs the source text (e.g. "0.5..9.5", `"a".."z"`).
type RangeTok ¶ added in v1.13.0
type RangeTok struct {
Tok string `parser:"(?! ')' ) @(Ident | Punct | String | CardExpr | Var | Operator)"`
}
RangeTok matches a single token of a @range operand: anything except the closing parenthesis that ends the annotation.
type RegexAnnot ¶
type RegexAnnot struct {
Pattern string `parser:"'@regex' '(' @String ')'"`
}
RegexAnnot parses: @regex("pattern")
type RegistryConfig ¶ added in v1.2.0
type RegistryConfig struct {
// PackageName is the Go package name for the generated code (required).
PackageName string
// UseAcronyms applies Go acronym naming conventions (e.g., "ID" not "Id").
UseAcronyms bool
// SkipAbstract excludes abstract types from entity/relation constants and EntityAttributes.
SkipAbstract bool
// Enums generates string constants from @values constraints.
Enums bool
// TypePrefix is the prefix for entity type constants (default "Type").
TypePrefix string
// RelPrefix is the prefix for relation type constants (default "Rel").
RelPrefix string
// SchemaText is the raw schema source. If non-empty, a SHA256-based SchemaHash is computed
// and annotations are extracted from comments.
SchemaText string
// SchemaVersion is a user-provided version string emitted as a constant.
SchemaVersion string
// TypedConstants generates typed string constants (type EntityType string, etc.)
// for compile-time safety instead of plain string constants.
TypedConstants bool
// JSONSchema generates JSON schema fragment maps for each entity/relation type.
JSONSchema bool
}
RegistryConfig specifies settings for generating a schema registry.
type RegistryData ¶ added in v1.2.0
type RegistryData struct {
PackageName string
EntityConstants []TypeConstCtx
RelationConstants []TypeConstCtx
Enums []EnumCtx
EntityParents []KVCtx
EntityAttributes []KVSliceCtx
AttrValueTypes []KVCtx
AttrEnumValues []KVSliceCtx
AttrRegex []KVCtx
AttrRange []KVCtx
RelationSchema []RelSchemaCtx
RelationAttrs []KVSliceCtx
AllEntityTypes []string
AllRelationTypes []string
// Metadata fields
EntityKeys []KVSliceCtx
EntityAbstract []string
RelationAbstract []string
RelationParents []KVCtx
SchemaHash string
SchemaVersion string
AttributeTypes []string
// Annotations from schema comments (# @key value)
EntityAnnotations []KVMapCtx
AttributeAnnotations []KVMapCtx
RelationAnnotations []KVMapCtx
// Typed constants (StrEnum-style)
TypedConstants bool
AttributeTypeConstants []TypeConstCtx
// JSON schema fragments
JSONSchema bool
EntityJSONSchema []JSONSchemaCtx
}
RegistryData holds all schema-derived data for registry code generation.
func BuildRegistryData ¶ added in v1.2.0
func BuildRegistryData(schema *ParsedSchema, cfg RegistryConfig) *RegistryData
BuildRegistryData populates a RegistryData from a parsed schema. The schema should have AccumulateInheritance() called before this. PackageName is required to render the result: RenderRegistry returns an error when it is empty.
type RelSchemaCtx ¶ added in v1.2.0
RelSchemaCtx describes a relation's role schema with N roles.
type RelatesDef ¶
type RelatesDef struct {
Role string `parser:"'relates' @Ident"`
IsList bool `parser:"( @'[' ']' )?"`
AsParent *AsClause `parser:"@@?"`
Annots []Annotation `parser:"@@*"`
}
RelatesDef parses: relates role-name[[]] [as parent-role] [@card(...)] The optional '[]' suffix marks a TypeQL 3.x ordered-list role.
type RelatesSpec ¶
type RelatesSpec struct {
// Role is the name of the role in the relation.
Role string
// AsParent specifies an overridden role from a parent relation type.
AsParent string
// Card specifies the cardinality of players allowed for this role.
Card string
// IsList indicates a TypeQL 3.x ordered-list role (relates role[]).
IsList bool
// Doc is the optional @doc annotation text.
Doc string
// Meta is the list of @meta annotations.
Meta []MetaSpec
}
RelatesSpec describes a "relates role" clause in a relation definition.
type RelationClause ¶
type RelationClause struct {
Relates *RelatesDef `parser:" @@"`
Owns *OwnsDef `parser:"| @@"`
Plays *PlaysDef `parser:"| @@"`
Sub *SubClause `parser:"| @@"`
}
RelationClause is one of: relates, owns, plays, or sub (comma-constraint form; see EntityClause).
type RelationDef ¶
type RelationDef struct {
Name string `parser:"'relation' @Ident"`
Parent *SubClause `parser:"@@?"`
Annots []Annotation `parser:"@@*"`
Comma string `parser:"','?"`
Clauses []RelationClause `parser:"( @@ ( ',' @@ )* )? ';'"`
}
RelationDef parses: relation name [sub parent] [annotations] [, clause...];
type RelationSpec ¶
type RelationSpec struct {
// Name is the name of the relation type.
Name string
// Parent is the name of the parent relation type if this is a subtype.
Parent string
// Abstract indicates whether the relation type is defined as abstract.
Abstract bool
// Doc is the optional @doc annotation text.
Doc string
// Meta is the list of @meta annotations.
Meta []MetaSpec
// Relates is a list of roles involved in this relation.
Relates []RelatesSpec
// Owns is a list of attributes owned by this relation type.
Owns []OwnsSpec
// Plays is a list of relation roles this relation type can play.
Plays []PlaysSpec
}
RelationSpec describes a TypeQL relation definition.
type RenderConfig ¶
type RenderConfig struct {
// PackageName is the name of the Go package for the generated code.
PackageName string
// ModulePath is the module import path for the 'gotype' package.
ModulePath string
// UseAcronyms, if true, applies Go acronym naming conventions (e.g., 'ID' instead of 'Id').
UseAcronyms bool
// SkipAbstract, if true, excludes abstract TypeDB types from the generated Go code.
SkipAbstract bool
// SchemaVersion is an optional string included in the generated file header.
SchemaVersion string
// Enums, if true, generates string constants from @values constraints on attributes.
Enums bool
// WarnWriter receives non-fatal generation warnings (unknown value types,
// undefined attributes, roles without a resolvable player). When nil,
// warnings are written to os.Stderr.
WarnWriter io.Writer
}
RenderConfig specifies the settings for generating Go code from a TypeQL schema.
func DefaultConfig ¶
func DefaultConfig() RenderConfig
DefaultConfig returns a standard RenderConfig with sensible defaults.
type RoleCtx ¶ added in v1.3.0
RoleCtx describes a single role in a relation: its name and which entity types can fill it.
type SimpleDef ¶
type SimpleDef struct {
Attribute *AttrDef `parser:" @@"`
Entity *EntityDef `parser:"| @@"`
Relation *RelationDef `parser:"| @@"`
Struct *StructDefP `parser:"| @@"`
Fun *FunDef `parser:"| @@"`
}
SimpleDef represents a single top-level definition within a TypeQL define block.
type StructDefP ¶
type StructDefP struct {
Name string `parser:"'struct' @Ident"`
Annots []Annotation `parser:"@@* (':' | ',')"`
Fields []StructFieldP `parser:"@@ (',' @@)* ','? ';'"`
}
StructDefP parses: struct name [annotations] (: | ,) field [, field]* [,] ; Supports both official TypeQL syntax (`:` separator, `name value type`) and legacy syntax (`,` separator, `value name type`).
type StructFieldP ¶
type StructFieldP struct {
FieldName string `parser:"( @Ident 'value' | 'value' @Ident )"`
ValueType string `parser:"@Ident"`
Optional bool `parser:"@'?'?"`
Annots []Annotation `parser:"@@*"`
}
StructFieldP parses a struct field in either official or legacy order:
- Official: field-name value type[?]
- Legacy: value field-name type[?]
type StructFieldSpec ¶
type StructFieldSpec struct {
// Name is the name of the field.
Name string
// ValueType is the TypeQL type of the field's value.
ValueType string
// Optional indicates whether the field is marked as optional in the schema.
Optional bool
// Doc is the optional @doc annotation text.
Doc string
// Meta is the list of @meta annotations.
Meta []MetaSpec
}
StructFieldSpec describes a single field within a TypeQL struct.
type StructSpec ¶
type StructSpec struct {
// Name is the name of the struct type.
Name string
// Doc is the optional @doc annotation text.
Doc string
// Meta is the list of @meta annotations.
Meta []MetaSpec
// Fields is a list of fields defined within the struct.
Fields []StructFieldSpec
}
StructSpec describes a TypeQL struct definition, which is a collection of named fields.
type SubClause ¶
type SubClause struct {
Parent string `parser:"'sub' @Ident"`
Annots []Annotation `parser:"@@*"`
}
SubClause parses: sub parent-name
type SubkeyAnnot ¶ added in v1.12.0
type SubkeyAnnot struct {
Key string `parser:"'@subkey' '(' @Ident ')'"`
}
SubkeyAnnot parses: @subkey(identifier)
type TQLFileSimple ¶
type TQLFileSimple struct {
Define string `parser:"'define'"`
Definitions []SimpleDef `parser:"@@*"`
}
TQLFileSimple is the top-level grammar for a TypeQL define block.
type TypeConstCtx ¶ added in v1.2.0
TypeConstCtx holds a Go constant name and its string value.
type ValuesAnnot ¶
type ValuesAnnot struct {
Values []string `parser:"'@values' '(' @String ( ',' @String )* ')'"`
}
ValuesAnnot parses: @values("a", "b", ...)