DolphinDB plugins currently have release200, release130, release120 and release110. Each plugin version corresponds to a DolphinDB server version. Please refer to the corresponding branch according to the server version you are using.
DolphinDB database supports dynamic loading of external plugins to extend system functionality. The plug-in can be written in C++, and it needs to be compiled into ".so" shared libraries or ".dll" shared library files.
Please switch to the corresponding branch to view the following listed directories for each plugin. The master branch doesn’t contain these directories.
include
The directory contains the class declarations and some tool class declarations for the core data structures of DolphinDB. These classes are important basic tools for implementing plug-ins.demo
The directory contains a demo plug-in implementation.Use the loadPlugin
function to load external plugins. This function accepts a file path, which describes the format of the plugin, for example:
loadPlugin("/YOUR_SERVER_PATH/plugins/odbc/PluginODBC.txt");
Starting from server version 1.20.0, plugins can be automatically loaded through the configuration parameter preloadModules. Please note that the plugin that needs to be preloaded must exist. Otherwise, there will be an exception when the server starts. Multiple plugins are separated by ',', for example:
preloadModules=plugins::mysql,plugins::odbc
DolphinDB uses a text file to describe the plugin. The file format is as follows: The first line describes the plugin name and shared library file name. Each of the following lines describes the mapping between a shared library function and the DolphinDB function.
module name, lib file
function name in lib, function name in DolphinDB, function type, minParamCount, maxParamCount, isAggregate
...
Explanation:
PluginDemo.txt:
demo,libPluginDemo.so
minmax,minmax,operator,1,1,0
foo,foo,system,1,1,0
The description file above defines a plugin named demo
. The shared library file is named libPluginDemo.so
.
The plugin exports two functions. The first function is named minmax
. The name of the function is also minmax
in DolphinDB. The function type is "operator" and accepts one parameter. The second function name is echo
, the name in DolphinDB is also echo
, the function type is "system" and accepts one argument.
After finishing the description file, you can start writing plugins. For content, please refer to demo
folder contents.
The compiler needs to use DolphinDB's core library libDolphinDB.so
, which implements the classes declared in include
directories.
cd demo
g++ -DLINUX -fPIC -DLOCKFREE_SYMBASE -c src/Demo.cpp -I../include -o Demo.o
g++ -fPIC -shared -o libPluginDemo.so Demo.o -lDolphinDB
Note:
After successful compilation, a shared library file named libPluginDemo.so will be generated under the directory.
Enter the following command in the DolphinDB console to load the plugin and use it.
>loadPlugin(Path to PluginDemo.txt); // Load the plugin
(minmax,echo)
>use demo; // Import the plugin's namespace
>demo::minmax([12,3,4]); // You can also use minmax([12,3,4])
[3,12]
>demo::echo("foo");
foo
>echo(1);
1
libBoardDB.so
in order to avoid the incompatibilities between different versions of the compiler ABI.