9.14 MLE

Use the MLE command to load JavaScript libraries to the database as MLE modules.

The sub-commands are:

Prerequisites

This command requires:

  • Oracle Database Release 23ai.
  • The CREATE TABLE privilege is required for the create-module sub-command. If creating a module in another schema, then the CREATE ANY TABLE privilege is required.

  • System privileges documented in the Oracle Database JavaScript Developer's Guide.

9.14.1 Create Module

Creates an MLE module.

Syntax

mle create-module {OPTIONS}

Options

Option Description
Required
-filename <filename> Specifies the path to a valid JavaScript file.
-module-name <module> Specifies the name of the module to create in the current schema.
Optional
-bundler <bundler> {rollup} Specifies the name of a supported program that can bundle a JavaScript file with its dependencies. See JavaScript with External Dependencies.
-bundler‑config <bundler‑config> {file} Specifies the name of a configuration file for the bundler program.
-if-not-exists Creates the module only if it does not exist.
-language <language> Specifies the name of a supported programming language. The default value is JavaScript.
-metadata <metadata> Specifies any valid JSON text that describes the module. This option is mutually exclusive with -metafile.
-metafile <metafile> Specifies the path to a valid JSON file that describes the module. This option is mutually exclusive with -metadata.
-sbom <sbom> {syft} Specifies the name of a supported program that can create a Software Bill of Materials.
-replace Replaces the module if it exists or create one if it does not exist.
-schema <schema> Specifies the name of an alternate schema to own the module.
–verbose Emits additional diagnostic information as the command makes progress.
–version <version> Specifies the version of the programming language.

JavaScript with External Dependencies

The Create Module sub-command can load a JavaScript file that refers to other JavaScript modules. To accomplish this, the MLE command bundles the specified JavaScript file with all its dependencies and uses the external rollup command.

  • Install rollup and syft

    For bundling external dependencies, install rollup. For SBOM (Software Bill of Materials), install syft. You can use brew install for both.

  • Configuring rollup execution

    The intended usage for bundling is to bundle a single JavaScript file that has external dependencies. For example, if bundling should exclude one or more external dependencies, then those exclusions would be specified in a configuration file specified with the -bundler‑config option. Not all bundling requires a configuration. In any case, the single JavaScript file to bundle is always specified with the ‑filename option, even if the input filename is specified in the configuration file.

  • Mutating dependency

    If you create an MLE module from a.js, modify c.js, and then create another MLE module from b.js, then you have two MLE modules with a mutated dependency, c.js. To avoid this, reorganize the code so that you create three MLE modules and avoid the bundling.

  • Debugging

    When a bundled JavaScript file is created by the host command (using the -bundler option), the resulting JavaScript file is not an exact representation of what exists on the file system. Therefore, when you attach a debugger to the MLE module's execution, you do not know which external JavaScript file and line number you are viewing.

9.14.2 Alter Module

Change an existing MLE module.

Syntax

mle alter-module {OPTIONS}

Options

Option Description
Required
-module-name <module> The name of the module to change in the current schema.
-metadata <metadata> Any valid JSON text that describes the module. This option is mutually exclusive with -metafile.
-metafile <metafile> The path to a valid JSON file that describes the module. This option is mutually exclusive with -metadata.
Optional
-if-exists Modify the module only if it exists.
–verbose Emit additional diagnostic information as the command makes progress.
-schema <schema> The name of an alternate schema that owns the module.

Examples

  • Modify an existing MLE module by updating the metadata and specifying the module name.
    SQL> mle alter-module -metadata '{"name":"getOrderTotal", "version":"1.1"}' -module-name abc
  • Display the MLE module metadata.
    SQL> select metadata from user_mle_modules where module_name = 'ABC'