TypeDB / TypeQL¶
Overview¶
TypeDB is a polymorphic database that uses its own query language,
TypeQL. The TypeDB generator converts a LinkML
schema into a TypeQL 3.x define block that can be loaded directly into a TypeDB server to
define the schema for your database.
Each LinkML class becomes a TypeDB entity type. Scalar slots become attribute types
and are attached to entity types via owns declarations. Slots whose range is another class
become relation types with corresponding plays declarations on the participating entities.
Type Mapping¶
LinkML type (URI) |
TypeDB value type |
Notes |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TypeDB 3.x has no native duration type |
Enum range |
|
Permitted values listed in an inline comment |
Unknown / unresolved |
|
Fallback; a warning comment is emitted |
Cardinality Annotations¶
identifier: true→@key(unique, mandatory)required: trueand not multivalued →@card(1..1)multivalued: true→@card(0..)
Abstract Classes¶
A class with abstract: true gets the TypeDB @abstract annotation on its entity
declaration.
Reserved Keywords¶
TypeDB has a set of reserved keywords (entity, relation, role, match,
insert, etc.). Any class or slot name that collides with a reserved keyword is
automatically renamed with a -attr or -rel suffix and a warning comment is
added to the output.
Usage¶
gen-typedb my_schema.yaml
To write to a file:
gen-typedb my_schema.yaml > schema.tql
Dependencies¶
The generator itself only produces text and has no runtime dependency on the TypeDB
driver. To run the integration tests (which connect to a live TypeDB 3.x server) you
need the optional typedb extras group:
uv sync --group typedb
Limitations¶
Enum permissible values are not enforced by TypeDB; they are recorded as comments only.
xsd:durationhas no native TypeDB equivalent and is stored asstring.Multiple inheritance (
mixins) is partially supported — each mixin’s slots are inlined asowns/playsdeclarations on the inheriting entity.
Docs¶
Command Line¶
gen-typedb¶
Generate TypeDB TypeQL schema definitions from a LinkML model.
gen-typedb [OPTIONS] YAMLFILE
Options
- -V, --version¶
Show the version and exit.
- -f, --format <format>¶
Output format
- Default:
'typeql'- Options:
typeql
- --metadata, --no-metadata¶
Include metadata in output
- Default:
True
- --useuris, --metauris¶
Use class and slot URIs over model uris
- Default:
True
- -im, --importmap <importmap>¶
Import mapping file
- --log_level <log_level>¶
Logging level
- Default:
'WARNING'- Options:
CRITICAL | ERROR | WARNING | INFO | DEBUG
- -v, --verbose¶
Verbosity. Takes precedence over –log_level.
- --mergeimports, --no-mergeimports¶
Merge imports into source file (default=mergeimports)
- --stacktrace, --no-stacktrace¶
Print a stack trace when an error occurs
- Default:
False
Arguments
- YAMLFILE¶
Required argument
Code¶
- class linkml.generators.typedbgen.TypeDBGenerator(schema: str | ~typing.TextIO | ~linkml_runtime.linkml_model.meta.SchemaDefinition | ~linkml.utils.generator.Generator | ~pathlib.Path, schemaview: ~linkml_runtime.utils.schemaview.SchemaView | None = None, format: str | None = None, metadata: bool = True, useuris: bool | None = None, log_level: int | None = 30, mergeimports: bool | None = True, source_file_date: str | None = None, source_file_size: int | None = None, logger: ~logging.Logger | None = None, verbose: bool | None = None, output: str | None = None, namespaces: ~linkml_runtime.utils.namespaces.Namespaces | None = None, directory_output: bool = False, base_dir: str = None, metamodel_name_map: dict[str, str] = None, importmap: str | ~collections.abc.Mapping[str, str] | None = None, emit_prefixes: set[str] = <factory>, metamodel: ~linkml.utils.schemaloader.SchemaLoader = None, stacktrace: bool = False, include: str | ~pathlib.Path | ~linkml_runtime.linkml_model.meta.SchemaDefinition | None = None)[source]¶
Generates TypeDB 3.x TypeQL schema definitions from a LinkML schema.
Output is a single
defineblock containing attribute types, entity types, and relation types derived from the LinkML schema.