This is open-source code that lets you secure or mask numbers (within Postgresql DB) for use as unique IDs that are 6-digits or more.
This is what they look like:
https://example.com/order/053124
/** | |
* Returns a Time Sortable ID with millisecond precision. | |
* | |
* Time component: 42 bits (2^42 = ~69 years) | |
* | |
* Random component: 22 bits (2^22 = 4,194,304) | |
* | |
* The time component is the count of milliseconds since 2020-01-01T00:00:00Z. | |
* | |
* Tags: tsid ulid snowflake id-generator generator time sortable sort order id |
CREATE SEQUENCE public.global_id_seq; | |
ALTER SEQUENCE public.global_id_seq OWNER TO postgres; | |
CREATE OR REPLACE FUNCTION public.id_generator() | |
RETURNS bigint | |
LANGUAGE 'plpgsql' | |
AS $BODY$ | |
DECLARE | |
our_epoch bigint := 1314220021721; | |
seq_id bigint; |