Share via


import ("M" Reference)

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

Modules may refer to declarations in other modules by using an import directive to name the module that contains the referenced declarations.

Syntax

There are two alternate syntaxes. The first one specifies import targets at the module level; the second one specifies targets at the member level. The following is the first syntax.

import ImportModules 
ImportModules:
    ImportModule  
    ImportModules  ,  ImportModule  
ImportModule:
    QualifiedIdentifier  ImportAlias(optional)  
ImportAlias:
    as  Identifier

ImportModules is a comma-separated list of module names.

Each module consists of:

  • A qualified identifier.

  • An optional import alias, which is just an identifier.

The second alternate definition is the following, which specifies targets at the member level.

import  QualifiedIdentifier  {  ImportMembers  }  ;  
ImportMembers:
    ImportMember  
    ImportMembers  ,  ImportMember  
ImportMember:
    Identifier  ImportAliasopt  
ImportAlias:
    as  Identifier

ImportMembers is a comma-separated list of member names.

Each member name consists of:

  • An identifier

  • An optional import alias, which is just an identifier.

Discussion

For a declaration to be referenced by other modules, the declaration must be explicitly exported using an export ("M" Reference) directive.

Within a module, any import directives must appear before any export directives, and any import directives must appear before any declarations.

Example

The following example shows the syntax using module names. The first code fragment defines the Contacts module, which exports the Person type.

module Contacts 
{
    export Person;
    type Address 
   {
      street: Text; 
      City: Text;
   }
    type Person  
   { 
      FirstName : Text; 
      Age : Integer32; 
   }
}

The Contacts.Address field can only be referenced from within the Contacts module. The Contacts.Person type can be referenced in any module that has an import directive for the Contacts module, as shown in the following code fragment.

module MyContacts 
{
    import Contacts;
    Friends : Person*;
}

The following example shows the syntax using member names.

module Contacts 
{
    export Person;
    export Address;
    type Address 
   {
      street: Text; 
      City: Text;
   }
    type Person  
   { 
      FirstName : Text; 
      Age : Integer32; 
   }
}

The Contacts.Address field can be referenced from within any module doing a module-based import. However, the following example does a member-based import, and so the Contacts.Person type can be referenced, but Contacts.Address cannot be.

module MyContacts 
{
    import Contacts {Person};
    Friends : Person*;
}

For import examples using aliases, see as ("M" Reference).

See Also

Concepts

export ("M" Reference)