2.1.1. Install rust through rustup.
curl https://sh.rustup.rs -sSf | sh
2.1.2. Prepare your postgres installation 2.1.3. Install pgx
cargo install cargo-pgx
2.1.4. Initialize pgx for the postgres version you have already installed
Handle the number accordingly.
cargo pgx init --pg14 $(which pg_config)
2.1.5. Install the extension
git clone https://github.com/spa5k/uids-postgres \
&& cd uids-postgres \
&& cargo pgx install
Check the included Dockerfile for the installation template.
CREATE EXTENSION IF NOT EXISTS uids;
- Generate a new KSUID
select generate_ksuid();
-----------------------------
28KKKI8lpDkK2lHbAdWdgJYoLWF
- Generate a KSUID bytes.
select generate_ksuid_bytes();
-----------------------------
\x0ef557bc9b5b8027f222e2b32ed65e91b6bb8eb6
- Generate a new NanoId with default size of 21
select generate_nanoid();
-----------------------------
FfuwjZHjS5j5rATHVyl8M
- Generate a NanoId with a custom size
select generate_nanoid_length(10);
-----------------------------
V2D2D7-dnw
- Generate a NanoId with a custom alphabets with length of 21
-- Length of the nanoid is first argument, while the alphabets one is second.
select generate_nanoid_c('1234567890abcdef');
-----------------------------
6df80ad84587f4a20838c
- Generate a NanoId with a custom alphabets and custom length
-- Length of the nanoid is first argument, while the alphabets one is second.
select generate_nanoid_length_c(10, '1234567890abcdef');
-----------------------------
050487bff0
- Generate a new Ulid
select generate_ulid();
-----------------------------
01G1JE4GXWC1A9PXHG0SXQDE1J
- Generate Ulid bytes
select generate_ulid_bytes();
-----------------------------
\x018064e2bff9e6bb876aa8948e50d9c6
- Generate Ulid from a custom string
select generate_ulid_from_string('01CAT3X5Y5G9A62F1rFA6Tnice');
-----------------------------
01CAT3X5Y5G9A62F1RFA6TN1CE