The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination.
However, when storing UUIDs in a database, there is a need for UUIDs to be optimized in a way that allows the database to search, order and index them quickly.
The ordered-uuid module implements the results of research by Karthik Appigatla, originally based on work done by Peter Zaitsev. It can typically be used with RDBMSs which allow storage of 16-bit binary fields (e.g. Binary(16) in MySQL/MariaDB).
Generate an ordered UUID, and return it as a string.
Convenience function which intakes an ordered UUID string, and returns it as a hex-encoded Buffer object.
Convenience function which intakes a hex-encoded binary Buffer object containing an ordered UUID, decodes it, and returns it as the original ordered-UUID string.
var OrderedUUID = require('ordered-uuid');
var orderedUuid = OrderedUUID.generate();
// '4352e80c5117dff996296b7531fbc4c0'
var binaryUuid = OrderedUUID.toBinary16(orderedUuid);
// <Buffer 43 52 e8 0c 51 17 df f9 96 29 6b 75 31 fb c4 c0>
var decodedUuid = OrderedUUID.fromBinary16(binaryUuid);
// '4352e80c5117dff996296b7531fbc4c0'
For all questions and issues, please open an Issue in GitHub.
Licensed liberally under MIT; see LICENSE for complete license text.