joa
03/05/2022, 10:43 PM(111 = client_id)
This would allow me to update only if the client_id
field/part of the new data (i.e. the POST data) was equal to "111". I have not been able to make any functions within Supabase at all, based on the code you suggested and based on the examples in the tutorials. Supabase only gives me syntax errors "near create" etc...joa
03/05/2022, 10:43 PM(111 = client_id)
This would allow me to update only if the client_id
field/part of the new data (i.e. the POST data) was equal to "111". I have not been able to make any functions within Supabase at all, based on the code you suggested and based on the examples in the tutorials. Supabase only gives me syntax errors "near create" etc...joa
03/05/2022, 10:44 PMjoa
03/05/2022, 10:45 PMjoa
03/05/2022, 10:47 PMjoa
03/05/2022, 10:50 PMid, project_id, client_id, sensor_value
and table project contains id, project_id, user_id, passhash
joa
03/05/2022, 10:51 PM{ "project_id": 33, "client_id": 77, "sensor_value": "on", "passhash": "adshahsdjahsd" }
joa
03/05/2022, 10:51 PMjoa
03/05/2022, 10:53 PM(project_id = ( SELECT project.project_id
FROM project
WHERE (project.passhash)::text = passhash AND project.project_id = project_id)
)
garyaustin
03/05/2022, 11:00 PMjoa
03/05/2022, 11:01 PMjoa
03/05/2022, 11:02 PMjoa
03/05/2022, 11:02 PMjoa
03/05/2022, 11:03 PMgaryaustin
03/05/2022, 11:05 PMgaryaustin
03/05/2022, 11:08 PMfor update using (
true
);
for update with check (
passhash in (
select passhash from project
where project_id = project.project_id
)
);
joa
03/05/2022, 11:11 PMjoa
03/05/2022, 11:12 PMpasshash in (
) refers to the field in the body. But what about a policy for insert, where the is no current row/data/passhash to compare against?garyaustin
03/05/2022, 11:12 PMgaryaustin
03/05/2022, 11:14 PMgaryaustin
03/05/2022, 11:15 PMjoa
03/05/2022, 11:31 PMjoa
03/05/2022, 11:33 PMproject_id
as welljoa
03/05/2022, 11:33 PMgaryaustin
03/05/2022, 11:33 PMjoa
03/05/2022, 11:34 PMgaryaustin
03/05/2022, 11:35 PMgaryaustin
03/05/2022, 11:36 PMjoa
03/05/2022, 11:36 PMjoa
03/05/2022, 11:38 PMgaryaustin
03/05/2022, 11:38 PMjoa
03/05/2022, 11:38 PMproject_id: 1, passhash: bbb
joa
03/05/2022, 11:39 PMproject_id: 2, passhash: bbb
garyaustin
03/05/2022, 11:39 PMjoa
03/05/2022, 11:39 PMjoa
03/05/2022, 11:39 PMjoa
03/05/2022, 11:40 PMjoa
03/05/2022, 11:40 PMproject_id 1, passhash aaa
and project_id 2, passhash bbb
(if you see what I mean)garyaustin
03/05/2022, 11:41 PMjoa
03/05/2022, 11:43 PMjoa
03/05/2022, 11:43 PM(passhash IN ( SELECT project.passhash
FROM project
WHERE (project.project_id = project.project_id)))
garyaustin
03/05/2022, 11:43 PMjoa
03/05/2022, 11:43 PMproject.
on both sides of the where clausejoa
03/05/2022, 11:43 PMjoa
03/05/2022, 11:44 PMWHERE (project_id = project.project_id)
then it just gets changed backjoa
03/05/2022, 11:44 PMgaryaustin
03/05/2022, 11:44 PMgaryaustin
03/05/2022, 11:44 PMjoa
03/05/2022, 11:45 PMgaryaustin
03/05/2022, 11:45 PMgaryaustin
03/05/2022, 11:46 PMjoa
03/05/2022, 11:46 PMproject.id
or somethinggaryaustin
03/05/2022, 11:46 PMjoa
03/05/2022, 11:48 PMjoa
03/05/2022, 11:48 PM(passhash IN ( SELECT project.passhash
FROM project
WHERE (event.project_id = project.id)))
joa
03/05/2022, 11:48 PMjoa
03/05/2022, 11:49 PMjoa
03/05/2022, 11:49 PMgaryaustin
03/05/2022, 11:49 PMjoa
03/05/2022, 11:51 PMgaryaustin
03/05/2022, 11:52 PMjoa
03/05/2022, 11:53 PMjoa
03/05/2022, 11:53 PMgaryaustin
03/05/2022, 11:53 PMjoa
03/05/2022, 11:54 PMjoa
03/05/2022, 11:54 PMgaryaustin
03/05/2022, 11:54 PMjoa
03/05/2022, 11:55 PMgaryaustin
03/05/2022, 11:55 PMjoa
03/05/2022, 11:56 PMgetDevId
you proposed) but that seems to have a whole new level of syntax (or UX) issuesjoa
03/05/2022, 11:56 PMjoa
03/05/2022, 11:56 PMgaryaustin
03/05/2022, 11:57 PMjoa
03/05/2022, 11:57 PMjoa
03/05/2022, 11:57 PMjoa
03/05/2022, 11:57 PMjoa
03/05/2022, 11:58 PMgaryaustin
03/05/2022, 11:58 PMjoa
03/05/2022, 11:58 PMjoa
03/05/2022, 11:58 PMgaryaustin
03/06/2022, 12:00 AMjoa
03/06/2022, 12:00 AMjoa
03/06/2022, 12:00 AMjoa
03/06/2022, 12:00 AMgaryaustin
03/06/2022, 12:00 AMjoa
03/06/2022, 12:00 AMjoa
03/06/2022, 12:00 AMgaryaustin
03/06/2022, 12:01 AMjoa
03/06/2022, 12:01 AMjoa
03/06/2022, 12:01 AMgaryaustin
03/06/2022, 12:02 AMjoa
03/06/2022, 12:02 AMjoa
03/06/2022, 12:02 AMjoa
03/06/2022, 12:02 AMgaryaustin
03/06/2022, 1:17 AMcreate or replace function get_hash_header()
returns text
language sql stable
as $$
select
(current_setting('request.headers', true)::json->>'hash-header')::text
$$;
Tested with a supabase .js rpc call:
const {data} = await supabase.rpc('get_hash_header')
data comes back as 'abc'
So you could use get_hash_header() in either the USING or the WITH CHECK in place passhash coming in the post body and you don't have to have a "fake" column that is not used and deal with it being in the table or not... You just do the project table select on id to see if passhash matches...