3.3 Managing JavaScript Modules

The SQL Developer extension for VS Code enables you to access and manage MLE (Multilingual Engine) objects such as MLE modules.

For more information about MLE, see Introduction to Oracle Database Multilingual Engine in the Oracle Database JavaScript Developer's Guide.

SQL Developer for VS Code allows the creation of JavaScript modules as schema objects, assuming the necessary privileges are in place. JavaScript module is a unit of MLE's language code stored in the database as a schema object. You can create, edit and delete JavaScript modules.

The actions available are:

3.3.1 Create a JavaScript Module

To create a JavaScript module:
  1. In the Connections panel, click the + icon or right-click JavaScript Modules and then click Create.

    The Create panel appears.

  2. In the MLE Module Name field, enter a name for the module.

    The SQL pane displays the DDL code for the JavaScript module.

  3. Click Apply.

    The module is saved and appears in the Connections panel under JavaScript Modules.

3.3.1.1 Example for Create a JavaScript Module

This example demonstrates the creation of the factorial_mod JavaScript module.

  1. In the Connections panel, click the + icon in the JavaScript Modules node and then click Create.
  2. In the MLE Module Name field, enter factorial_mod.
  3. Click Apply.

    The module appears under JavaScript Modules in the Connections panel.

  4. In the Connections panel, expand JavaScript Modules, right-click factorial_mod and select Open.

    The factorial_mod module pane appears.

  5. Enter the following JavaScript function:
    export function factorial(num) {
        if(num < 0) {
            return -1;
        } else if (num == 0) {
            return 1;
        } else {
            return(num * factorial(num-1));
        }
    }
  6. Click the Compile icon to save the JavaScript code.

    Note:

    Alternatively, you can save the code by using ctr + s or cmd + s.

To import a module to an MLE environment, see Example for Create an MLE Environment.

3.3.2 Open a JavaScript Module

To open a JavaScript module:

  1. In the Connections panel, select the module name under JavaScript Modules, or right-click the module name and click Open.

    If the module is newly created using the Create action in the context menu, the module's content is //add you code here.

    You can add code or modify the existing code in the module. If the code has any syntax errors, the errors are underlined and the file's name turns to red. Also, the syntax errors appear in the Problems panel.

  2. Click the Compile icon to save the code to the database.

    After compiling the module, the result is displayed in the Script Output panel. If the execution finishes with errors, these appear in the Problems panel.

3.3.3 Show JavaScript Module Details

To show details about a selected module, after opening the module, click the Show Details Panel icon, which is located right next to the Compile icon.

The Details panel has three tabs: Privileges, Details and Errors.

If there are any errors in the saved module, the line and position column displays the line,position as a link that takes the cursor to the exact location of the syntax error in the module's file.

You can hide the Details panel by clicking the Hide Details Panel icon.

3.3.4 Compile JavaScript Module

To compile a selected JavaScript module:

  1. In the Connections panel, select the module to compile, right-click and select Compile.

    The Compile panel appears.

  2. Click Apply.

To compile all MLE modules for the connection, right-click JavaScript Modules and select Compile All.

To compile all invalid modules for the connection, right-click JavaScript Modules and select Compile All Invalid.

3.3.5 Delete a JavaScript Module

In the Connections panel, select the module to delete, right-click and select Drop. The Drop panel appears. Click Apply.