Skip to main content

Use a plugin

Once a plugin is installed for a specific service, it can be used with Rhai using the import statement.

// Import the plugin stored in the `plugins` directory via a symbolic link.
// All functions from the plugin are accessible via the `my_plugin` namespace
// in that example.
import "plugins/my_plugin" as my_plugin;

It is then possible to use the functionnalities exposed by the plugin via the plugin namespace.


After installing the MySQL plugin, the plugin can be used the following way:

import "plugins/libvsmtp_plugin_mysql" as mysql;

/// Create a pool of connection to a MySQL database.
export const bridge = mysql::connect(#{
url: "mysql://localhost/?user=john&password=doe",
timeout: "1m",
connections: 10,