Use cuid2
from directly within PostgreSQL.
This allows you to write DDL like:
CREATE TABLE foo (
id TEXT DEFAULT cuid2_create_id() PRIMARY KEY,
name TEXT
);
then inserting data:
INSERT INTO foo (name) values ('Foo');
and running SELECT * from foo;
will return something like
id | name
--------------------------+------
v11s7ykor7sv3uo1lcdkgs1p | Foo
(1 row)
This would not be possible without pgrx
, which made it so easy. Thank you!