RPC 函数详情
获取漫画更新
获取最近更新的漫画列表
按 latest_chapter_updated_at 降序返回最近有章节更新的漫画,主要用于首页「最近更新」模块。
函数签名
CREATE FUNCTION get_recent_comics(
limit_count integer DEFAULT 12
) RETURNS TABLE (
id bigint,
title text,
summary text,
cover_url text,
poster_url text,
lock_status text,
category_name text,
latest_chapter_title text,
latest_chapter_updated_at timestamptz
) LANGUAGE plpgsql;参数
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
limit_count | integer | 12 | 返回条数,控制列表长度 |
返回字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | bigint | 漫画 ID |
title | text | 漫画标题 |
summary | text | 简介 |
cover_url | text | 封面图地址 |
poster_url | text | 海报图地址 |
lock_status | text | 锁定状态(用于标识是否需要 VIP) |
category_name | text | 分类名称(LEFT JOIN categories) |
latest_chapter_title | text | 最新章节标题 |
latest_chapter_updated_at | timestamptz | 最新章节更新时间 |
实现逻辑
函数从 comics 表 LEFT JOIN categories,筛选 latest_chapter_updated_at IS NOT NULL(排除从未发布章节的漫画),按更新时间降序取 limit_count 条。
SELECT c.id, c.title, c.summary, c.cover_url, c.poster_url,
c.lock_status, cat.name AS category_name,
c.latest_chapter_title, c.latest_chapter_updated_at
FROM comics c
LEFT JOIN categories cat ON c.category_id = cat.id
WHERE c.latest_chapter_updated_at IS NOT NULL
ORDER BY c.latest_chapter_updated_at DESC
LIMIT limit_count;latest_chapter_title 和 latest_chapter_updated_at 是 comics 表的冗余字段,由触发器在章节变更时自动更新,因此本函数无需 JOIN chapters 表。
安全属性
- SECURITY DEFINER: 否(以调用者身份执行,受 comics 表 RLS 约束)
- VOLATILE: 是(默认,每次调用都重新查询)
调用示例
// 默认 12 条
val recent = supabase.postgrest
.rpc("get_recent_comics")
.decodeList<RecentComic>()
// 指定数量
val recent20 = supabase.postgrest
.rpc("get_recent_comics", buildJsonObject {
put("limit_count", 20)
})
.decodeList<RecentComic>()// 默认 12 条
const { data } = await supabase.rpc('get_recent_comics')
// 指定数量
const { data } = await supabase.rpc('get_recent_comics', {
limit_count: 20
})