UniqueID

The DolphinDB UniqueID plugin provides a lightweight solution for generating unique identifiers. Users can set the initial value and retrieve auto-increment IDs on DolphinDB server. As an alternative to UUIDs, the plugin provides short and readable IDs on demand.

Installation (with installPlugin)

Required server version: DolphinDB 2.00.13 or higher

Supported OS: Linux x86-64, Linux ABI

Installation Steps:

(1) Use listRemotePlugins to check plugin information in the plugin repository.

login("admin", "123456");
listRemotePlugins()

(2) Invoke installPlugin for plugin installation.

installPlugin("UniqueID");

(3) Use loadPlugin to load the plugin before using the plugin methods.

loadPlugin("UniqueID");

Method References

createGenerator

Syntax

UniqueID::createGenerator(name[, initUid = 1]);

Parameters

  • name: A STRING scalar indicating the name of the UID generator.
  • initUid (optional): A LONG scalar indicating the initial value. It can be negative. The default value is 1.

Details

Creates and returns a UID generator named name.

getGenerator

Syntax

UniqueID::getGenerator(name);

Parameters

  • name: A STRING scalar indicating the name of a UID generator.

Details

Returns the UID generator named name.

newUid

Syntax

UniqueID::newUid(generator[, size=1]);

Parameters

  • generator: The UID generator returned by method createGenerator or getGenerator.
  • size (optional): An INT scalar indicating the total number of IDs to be generated. The default value is 1.

Details

Generates and returns size IDs.

Return value: A LONG scalar or a vector.

listGenerator

Syntax

UniqueID::listGenerator();

Details

Returns the names of all UID generators and latest IDs on the server.

Return value: A table.

destroyGenerator

Syntax

UniqueID::destroyGenerator(name|generator);

Parameters

  • name: A STRING scalar indicating the name of a UID generator.
  • generator: The UID generator returned by method createGenerator or getGenerator.

Details

Destroys the UID generator.

No return value.

setLogLevel

Syntax

UniqueID::setLogLevel(logLevel)

Details

Sets the minimum log level for the plugin. The system outputs plugin logs at the specified level and above. The default level is INFO. This function only sets the plugin log level and does not affect the log level of the DolphinDB server.

Parameters

logLevel: A string specifying the log level. The valid values, in ascending order of severity, are DEBUG, INFO, WARNING, and ERROR.

Returns

None.

Example

Set the minimum log level to WARNING. After this setting, the system outputs only plugin logs at the WARNING and ERROR levels.

UniqueID::setLogLevel(WARNING)

getLogLevel

Syntax

UniqueID::getLogLevel()

Details

Gets the current log level of the plugin.

Parameters

None.

Returns

A string indicating the current log level.

Example

UniqueID::getLogLevel() // Output: 'INFO'

Usage Example

gen = UniqueID::createGenerator("mygen",10);
id = UniqueID::newUid(gen);
print(id);
// output:10
ids = UniqueID::newUid(gen, 5);
print(ids);
// [11,12,13,14,15]
UniqueID::destroyGenerator(gen); 
// UniqueID::destroyGenerator("mygen");