-
-
Save abevoelker/ecaea89e33ff67e943f2ad1aea3c9552 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE products ( | |
id BIGSERIAL, | |
title TEXT NOT NULL, | |
hashid TEXT NOT NULL | |
); | |
CREATE FUNCTION products_pre_insert() RETURNS trigger AS $$ | |
BEGIN | |
NEW.hashid := gen_hashid('products_secret_salt_here', 3, NEW.id); | |
RETURN NEW; | |
END; | |
$$ LANGUAGE plpgsql; | |
CREATE TRIGGER products_pre_insert BEFORE INSERT ON products FOR EACH ROW EXECUTE PROCEDURE products_pre_insert(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment