25 lines
687 B
PL/PgSQL
25 lines
687 B
PL/PgSQL
-- ============================================================================
|
|
-- NOTIFICATION RPC FUNCTIONS
|
|
-- Helper functions for notification queries
|
|
-- ============================================================================
|
|
|
|
-- Get unread notification count for a user
|
|
create or replace function get_unread_notification_count(p_user_id uuid)
|
|
returns integer
|
|
language plpgsql
|
|
stable
|
|
security definer
|
|
as $$
|
|
begin
|
|
return (
|
|
select count(*)::integer
|
|
from notifications
|
|
where user_id = p_user_id
|
|
and is_read = false
|
|
);
|
|
end;
|
|
$$;
|
|
|
|
-- Grant execute permission to authenticated users
|
|
grant execute on function get_unread_notification_count(uuid) to authenticated;
|