-- Function to count tools per category CREATE OR REPLACE FUNCTION get_tool_counts() RETURNS TABLE ( category_id BIGINT, count TEXT ) LANGUAGE SQL SECURITY DEFINER AS $$ SELECT category_id, COUNT(*)::TEXT as count FROM tools_categories GROUP BY category_id; $$; -- Function to count news items per category CREATE OR REPLACE FUNCTION get_news_counts() RETURNS TABLE ( category_id BIGINT, count TEXT ) LANGUAGE SQL SECURITY DEFINER AS $$ SELECT category_id, COUNT(*)::TEXT as count FROM news_categories GROUP BY category_id; $$; -- Function to count blog posts per category CREATE OR REPLACE FUNCTION get_blog_counts() RETURNS TABLE ( category_id BIGINT, count TEXT ) LANGUAGE SQL SECURITY DEFINER AS $$ SELECT category_id, COUNT(*)::TEXT as count FROM blog_posts_categories GROUP BY category_id; $$; -- Allow public access to these functions GRANT EXECUTE ON FUNCTION get_tool_counts() TO PUBLIC; GRANT EXECUTE ON FUNCTION get_news_counts() TO PUBLIC; GRANT EXECUTE ON FUNCTION get_blog_counts() TO PUBLIC;