Skip to main content
Version: 0.5.1

Plugin

If you want to extend Platformatic DB features, it is possible to register a plugin, which will be in the form of a standard Fastify plugin.

The config file will specify where the plugin file is located as the example below:

{
...
"plugin": {
"path": "./plugin/index.js"
}
}

The path is relative to the config file path.

Since it uses fastify-sandbox under the hood, all other options of that package may be specified under the plugin property.

Once the config file is set up, you can write your plugin to extend Platformatic DB API or write your custom business logic.

You should export an async function which receives a parameters

  • app (FastifyInstance) that is the main fastify instance running Platformatic DB
  • opts all the options specified in the config file after path
  • You can always access Platformatic data mapper through app.platformatic property.

Check some examples.

Hot Reload

Plugin file is being watched by fs.watch function.

You don't need to reload Platformatic DB server while working on your plugin. Every time you save, the watcher will trigger a reload event and the server will auto-restart and load your updated code.

tip

At this time, on Linux, file watch in subdirectories is not supported due to a Node.js limitation (documented here).