Search
ctrl/
Ask AI
Light
Dark
System

Modules

This section describes the SDL commands pertaining to modules.

Declare an empty module:

Copy
module my_module {}

Declare a module with some content:

Copy
module my_module {
    type User {
        required name: str;
    }
}

Define a module corresponding to the more explicit DDL commands.

module ModuleName "{"
  [ schema-declarations ]
  ...
"}"

Define a nested module.

module ParentModuleName "{"
  [ schema-declarations ]
  module ModuleName "{"
    [ schema-declarations ]
  "}"
  ...
"}"

The module block declaration defines a new module similar to the create module command, but it also allows putting the module content as nested declarations:

schema-declarations

Define various schema items that belong to this module.

Unlike create module command, a module block with the same name can appear multiple times in an SDL document. In that case all blocks with the same name are merged into a single module under that name. For example:

Copy
module my_module {
    abstract type Named {
        required name: str;
    }
}

module my_module {
    type User extending Named;
}

The above is equivalent to:

Copy
module my_module {
    abstract type Named {
        required name: str;
    }

    type User extending Named;
}

Typically, in the documentation examples of SDL the module block is omitted and instead its contents are described without assuming which specific module they belong to.

It’s also possible to declare modules implicitly. In this style SDL declaration uses fully-qualified name for the item that is being declared. The module part of the fully-qualified name implies that a module by that name will be automatically created in the schema. The following declaration is equivalent to the previous examples, but it declares module my_module implicitly:

Copy
abstract type my_module::Named {
    required name: str;
}

type my_module::User extending my_module::Named;

A module block can be nested inside another module block to create a nested module. If you want reference an entity in a nested module by its fully-qualified name, you will need to reference all of the containing modules’ names: <ParentModuleName>::<ModuleName>::<EntityName>