This project is stable: bugs are being fixed.
Optimized for databases
- The first 36 bits are dedicated to the Unix Timestamp: seconds since 1st January 1970 (unixts)
- The next 12 bits are dedicated to providing sub-second encoding for the Nanosecond precision (nsec).
- The next 4 bits are dedicated to the version (ver).
- The next 18 bits are dedicated to providing sub-second encoding for the Nanosecond precision (nsec).
- The next 8 bits are dedicated a monotonic clock sequence counter (seq).
- The last 50 bits are filled out with random data to pad the length and provide uniqueness (rand).
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| unixts |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|unixts | nsec | ver | nsec |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| nsec | seq | rand |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| rand |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
This version is the same as the v1 but it does not contain seq bits.
The lack of monotonic clock sequence allows generation without a generator.
- The first 36 bits are dedicated to the Unix Timestamp: seconds since 1st January 1970 (unixts)
- The next 12 bits are dedicated to providing sub-second encoding for the Nanosecond precision (nsec).
- The next 4 bits are dedicated to the version (ver).
- The next 18 bits are dedicated to providing sub-second encoding for the Nanosecond precision (nsec).
- The last 58 bits are filled out with random data to pad the length and provide uniqueness (rand).
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| unixts |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|unixts | nsec | ver | nsec |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| nsec | rand |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| rand |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
This module also exports some utility functions for working with LUUID.
add_hyphensremove_hyphensparseto_bytesfrom_bytes
In FirebirdSQL, LUUID can be stored just like any UUID, using the type BINARY(16).
FirebirdSQL provides functions to transform UUID from BINARY(16) TO CHAR(36) (UUID_TO_CHAR())
and the other way around (CHAR_TO_UUID()). These functions work correctly with LUUID.
This library provides the utility functions to_bytes and from_bytes.
to_bytestransforms a luuidstringinto a[]u8from_bytestransforms a luuid[]u8to astringWith these you can bind and retrieve[]u8to and fromBINARY(16)columns. No moreSELECT UUID_TO_CHAR(...)andINSERT CHAR_TO_UUID(...)in your queries.
Originally an implementation this proposed UUIDv7 design. Subsequently, this design was scrapped, and the final UUIDv7 design was implemented in vlib. This change prompted me to deviate from the original structure to gain 10 bits of uniqueness guarantees. I achieved this by removing the 2 variant bits and the 8 fractional nanosecond bits as discussed here, This modification still maintains full UUID compatibility with FirebirdSQL's UUID_TO_CHAR() and CHAR_TO_UUID() functions.