Jorf
01/31/2022, 9:48 PMcreate or replace function add_rating_count_artist (artistid integer)
returns void as
$$
update artists
set ratings = ratings + 1
where id = artistid;
$$
language sql volatile;
Then in my app I call:
async function addRatingCountToArtist(artistId) {
const { data, error } = await supabase.rpc( 'add_rating_count_artist', { artistid: artistId })
}
When I check the db, the ratings value has not changed. FYI, the artistId I'm passing in is a number. table name is artists, id is an int4, ratings is an int4 . Any ideas? Thank youScott P
01/31/2022, 9:53 PMconsole.log({ error }), it should give you some more insight into what the problem wasJorf
01/31/2022, 9:55 PMasync function addRatingCountToArtist(artistId) {
console.log('in add rating count to artist', artistId)
const { data, error } = await supabase.rpc( 'add_rating_count_artist', { artistid: artistId })
if (error) {
console.log('error adding rating count to artist', error)
} if (data) {
console.log('data from adding rating count to artist', data)
}
}
the first console log is firing, but the data or error ones aren'tsilentworks
01/31/2022, 10:10 PMJorf
01/31/2022, 10:14 PMSuccess. No rows returnedJorf
01/31/2022, 10:14 PMJorf
01/31/2022, 10:15 PMsyntax error at or near "add_rating_count_artist"Jorf
01/31/2022, 10:16 PMadd_rating_count_artist(1) in the sql editor.Jorf
01/31/2022, 10:16 PMsilentworks
01/31/2022, 10:16 PMJorf
01/31/2022, 10:26 PMartists tablesilentworks
01/31/2022, 10:29 PMJorf
01/31/2022, 10:29 PMadd_one_point('Henrietta') return syntax error at or near "add_one_point", function is create or replace function add_one_point (username text)
returns void as
$$
update profiles
set points = points + 1
where name = username;
$$
language sql volatile;
thank you @User !silentworks
01/31/2022, 10:40 PMsilentworks
01/31/2022, 10:40 PMselect add_rating_count_artist(1)Jorf
01/31/2022, 10:41 PMJorf
01/31/2022, 10:42 PMsilentworks
01/31/2022, 10:42 PMsilentworks
01/31/2022, 10:43 PMjs
const { data, error } = await supabase.rpc( 'add_rating_count_artist', { artistid: parseInt(artistId) })Jorf
01/31/2022, 10:46 PMparseInt, i also added typeof to the console log it's a numbersilentworks
01/31/2022, 10:48 PMJorf
01/31/2022, 10:49 PMconst { data, error } = await supabase.rpc( 'add_rating_count_artist', { artistid: 1 }), didn't work 🙂silentworks
01/31/2022, 10:57 PMsilentworks
01/31/2022, 10:57 PMsilentworks
01/31/2022, 10:58 PM.rpcJorf
01/31/2022, 10:59 PMsilentworks
01/31/2022, 11:00 PMSECURITY DEFINER after volatilesilentworks
01/31/2022, 11:00 PMJorf
01/31/2022, 11:00 PMJorf
01/31/2022, 11:04 PM