Zarckk
05/16/2022, 2:17 PMNeedle
05/16/2022, 2:17 PMgaryaustin
05/16/2022, 2:32 PMNeedle
05/16/2022, 2:32 PMZarckk
05/16/2022, 2:42 PMZarckk
05/16/2022, 2:43 PMif (req.method === 'POST') {
const { message } = req.body;
await supabaseClient.from('posts').insert([
{
content: message.content,
user_id: message.userId,
},
]);
return res.status(201).json({});
}
Zarckk
05/16/2022, 2:44 PMif (req.method === 'GET') {
let { data: messages } = await supabaseClient
.from('posts')
.select(
content,
id,
created_at,
edited_at,
user_id
)
.order('created_at', { ascending: false });
return res.status(200).json({
messages,
});
}
Zarckk
05/16/2022, 2:46 PMlet { data: messages } = await supabaseClient
.from('posts')
.select(
content,
id,
created_at,
user_id,
user (
name
)
)
.order('created_at', { ascending: false });
garyaustin
05/16/2022, 2:48 PMgaryaustin
05/16/2022, 2:51 PMZarckk
05/16/2022, 2:55 PMZarckk
05/16/2022, 2:56 PMZarckk
05/16/2022, 3:13 PMgaryaustin
05/16/2022, 3:19 PMZarckk
05/16/2022, 3:53 PMid
, that's good. But I don't know how to insert raw_user_meta_data
which contains the user name. And I have to do something in the trigger functions, but I did not get (due to my bad english) how to proceed.
begin
insert into public.profiles(id)
values(new.id);
return new;
end;
Zarckk
05/16/2022, 4:17 PMbegin
insert into public.profiles(id, name)
values(new.id, new.raw_user_meta_data->>'name');
return new;
end;
Needle
05/16/2022, 4:18 PM