From c19a46b73659e83cf731296feb1ef8a810fd85c4 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Sat, 10 Jun 2023 13:02:20 -0500 Subject: [PATCH] fix: hashed_text and email are text newtypes --- schema/010_email.sql | 2 +- schema/010_hashed_text.sql | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/schema/010_email.sql b/schema/010_email.sql index ed1821e..cf885a1 100644 --- a/schema/010_email.sql +++ b/schema/010_email.sql @@ -1 +1 @@ -create type public.email as (email text); +select create_newtype_text('public.email'); diff --git a/schema/010_hashed_text.sql b/schema/010_hashed_text.sql index 1cde164..838e873 100644 --- a/schema/010_hashed_text.sql +++ b/schema/010_hashed_text.sql @@ -1,10 +1,4 @@ -create type hashed_text as (hashed text); - -create function hashed_text_string(hashed hashed_text) - returns text - language sql - immutable - as 'select (hashed.hashed);'; +select create_newtype_text('public.hashed_text'); create function hash_text(plain text) returns hashed_text @@ -12,7 +6,7 @@ create function hash_text(plain text) immutable as $$ begin - return row(crypt(plain, gen_salt('bf'))); + return hashed_text_of_string(crypt(plain, gen_salt('bf'))); end; $$; @@ -22,6 +16,6 @@ create function hashed_text_matches(plain text, hashed hashed_text) immutable as $$ begin - return hashed_text_string(hashed) = crypt(plain, hashed_text_string(hashed)); + return hashed_text_to_string(hashed) = crypt(plain, hashed_text_to_string(hashed)); end; $$;