[supabase] 유저 코멘트 페이징 함수

김동욱·2024년 2월 29일
0
create
or replace function get_user_comments (param_user_id int) returns table (
  comment_id bigint,
  content text,
  user_id bigint,
  image_id bigint,
  preview_url text,
  created_at timestamp
) as $$
BEGIN
    RETURN QUERY
    SELECT
        tuc.comment_id,
        tuc.comment_content,
        tuc.comment_user_id,
        tii.image_id,
        tii.preview_url,
        tuc.comment_created_at
    FROM 
        tb_user_comment tuc
    INNER JOIN 
        tb_image_info tii ON tuc.comment_image_id = tii.image_id
    WHERE 
        tuc.comment_user_id = param_user_id
        AND tuc.comment_is_deleted = false
    ORDER BY 
        tuc.comment_created_at DESC;
END;
$$ language plpgsql;

select
  *
from
  get_user_comments (3);

create
or replace function get_paginated_user_comments (param_user_id int, param_offset_val int) returns table (
  comment_id bigint,
  content text,
  user_id bigint,
  image_id bigint,
  preview_url text,
  created_at timestamp
) as $$
BEGIN
    RETURN QUERY
    SELECT
        tuc.comment_id,
        tuc.comment_content,
        tuc.comment_user_id,
        tii.image_id,
        tii.preview_url,
        tuc.comment_created_at
    FROM 
        tb_user_comment tuc
    INNER JOIN 
        tb_image_info tii ON tuc.comment_image_id = tii.image_id
    WHERE 
        tuc.comment_user_id = param_user_id
        AND tuc.comment_is_deleted = false
    ORDER BY 
        tuc.comment_created_at DESC
    LIMIT 8 OFFSET param_offset_val;
END;
$$ language plpgsql;


select
  *
from
  get_paginated_user_comments (3, 16);

페이징네이션 추가

profile
백엔드 개발자

0개의 댓글