您好,我使用带有 4 个参数的 supabase ui 创建了一个 postgres 函数。
函数定义为
begin
insert into public.rooms (created_by_id, room_manager_id, room_name, room_key,starting_balance,room_open,player_id_list)
values (
cbi,
cbi,
rn,
rk,
sb,
true,
ARRAY[] :: uuid[]
);
UPDATE public.players
SET room_id_list = array_append(room_id_list, (SELECT id FROM public.rooms WHERE room_name = rn))
WHERE id = cbi;
end;
public.rooms 表具有此行级策略检查:
(auth.uid() = room_manager_id)
的角色为 authenticated
for INSERT
.
当我像这样从 nextjs api 路由函数调用此函数时,
const cbi : string= session.user.id
const rn : string= req.body.room_name
const rk : string= req.body.room_key
const sb : number= req.body.starting_balance
let { data, error } = await supabase.rpc("create_room", {cbi, rn, rk, sb} );
if (error) console.error("rpc crete_room error : ",error);
else console.log("rpc create_room success : ",data);
这给了我一个错误,
{
code: 'PGRST202',
details: 'Searched for the function public.create_room with parameter cbi or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache.',
hint: null,
message: 'Could not find the function public.create_room(cbi) in the schema cache'
}
我已经检查了参数名称是否与我在 rpc args 中传递的参数匹配
您需要在 RPC 调用中指定每个参数,即:
let { data, error } = await supabase
.rpc("create_room",
{"cbi":cbi, "rn":rn, "rk":rk, "sb":sb }
);