From bd6ca79338c2e9034c2dd7e9608a6500dd1df1e4 Mon Sep 17 00:00:00 2001 From: Raphael Arce Date: Fri, 11 Oct 2024 16:58:45 +0200 Subject: [PATCH] feat: add function to check if username is taken Signed-off-by: Raphael Arce --- ...241011145739_add_is_username_taken_function.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 supabase/migrations/20241011145739_add_is_username_taken_function.sql diff --git a/supabase/migrations/20241011145739_add_is_username_taken_function.sql b/supabase/migrations/20241011145739_add_is_username_taken_function.sql new file mode 100644 index 00000000..bef9a0b6 --- /dev/null +++ b/supabase/migrations/20241011145739_add_is_username_taken_function.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE FUNCTION is_username_taken(given_username text) +RETURNS BOOLEAN AS $$ +DECLARE + is_username_taken BOOLEAN; +BEGIN + -- Check if the username exists in the profile table + SELECT EXISTS(SELECT 1 FROM public.profiles WHERE username = given_username) INTO is_username_taken; + + -- Return the result + RETURN is_username_taken; +END; +$$ +LANGUAGE plpgsql +SECURITY DEFINER;