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
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
orgetGenerator
. - 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
orgetGenerator
.
Details
Destroys the UID generator.
No return value.
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");