rafael
02/04/2023, 1:59 AMconst { data: user_inventory, error } = await Supabase.from("user_inventory")
.select(
`id,
owner_id,
p:product_id (
id,
name,
type,
alternative_name,
code,
hex_color,
barcode,
brand (name, logo)
),
quantity`
)
.ilike("p.name", `%${term}%`)
.ilike("p.alternative_name", `%${term}%`)
.ilike("p.code", `%${term}%`);
DanMossa
02/04/2023, 2:07 AMjoshbochu
02/04/2023, 3:17 AMposts
table, and built an index to maintain an invariant such that users can only post once per day (code attached below)
when they haven't posted that day i can just use an insert query no problem
when they do i can't figure out how to use the supabase API to manage this (perhaps using the onConflict
on the upsert
api?) - get an error:
"there is no unique or exclusion constraint matching the ON CONFLICT specification'
when i provide the following comma seperated cols: user_id, inserted_at
all i want to do is update the same row for a given day with the post text.
table query
create table posts (
id bigint generated by default as identity primary key,
user_id uuid references auth.users not null,
post text check (char_length(post) > 0),
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
);
alter table posts enable row level security;
create policy "Individuals can create posts." on posts for
insert with check (auth.uid() = user_id);
create policy "Individuals can view their own posts. " on posts for
select using (auth.uid() = user_id);
create policy "Individuals can update their own posts." on posts for
update using (auth.uid() = user_id);
create policy "Individuals can delete their own posts." on posts for
delete using (auth.uid() = user_id);
index query:
create unique index unique_posts_per_day
on posts (user_id, date_trunc('day', inserted_at at time zone 'utc'));
?????
02/04/2023, 3:36 AMmansedan
02/04/2023, 4:23 AMsql
DECLARE
match_count float;
count_losses float;
total_bets float;
percent_match NUMERIC;
BEGIN
-- count the number of rows that match the specified value in the specificed column
SELECT COUNT(*) INTO match_count FROM plays WHERE status = 'WIN' AND profile = NEW.profile;
SELECT COUNT(*) INTO count_losses FROM plays WHERE status = 'LOSS' and profile = NEW.profile;
if (match_count + count_losses) > 0 then
-- calculate percentage.
total_bets = (match_count + count_losses)::float;
percent_match = (match_count / total_bets)::float;
update profiles set win_record=percent_match where id= NEW.profile;
end if;
return new;
end
When we use a static string value in place of NEW.profile
that is the ID of a profile we know exists in the table, this function works perfectly. profile
is a foreign relation UUID column.
Can anyone point me in the right direction here?kyds3k
02/04/2023, 5:53 AMconst updates = {
team_id: user.id,
edition: edition_id,
round: round_id,
question: question_id,
answer: formdata.answer,
music_answer: formdata.music_answer,
created_at: new Date().toISOString(),
};
team_id
is a uuid and the same as the User uuid from auth.
If the team_id
, edition_id
, round_id
, and question_id
are all the same as in an existing row, that row should be updated with the other data (answer, music_answer, created_at
)
If there's no that has the same values for those, then a new row should be created.
Is this possible?Hal
02/04/2023, 5:58 AMelliott
02/04/2023, 7:28 AMwith clusters as (
WITH pts AS (
select
ST_Point(p.longitude, p.latitude) as geom,
p.selfie_path as selfie_path,
p.created_at
from
public.profiles as p
where
ST_Within(
ST_Point(p.longitude, p.latitude),
ST_MakeBox2D(
ST_Point(-123.16979495879038, 36.9067914918534),
ST_Point(-121.52930534951477, 38.988128574691444)
)
)
)
SELECT
ST_ClusterKMeans(geom, 3) OVER() AS clst_id,
ST_AsText(geom) AS geom,
selfie_path
FROM
pts
)
select
ST_Y(st_centroid(ST_Collect(geom))) as latitude,
ST_X(st_centroid(ST_Collect(geom))) as longitude,
json_agg(selfie_path) as selfie_paths
from
clusters
group by
clst_id
I've attached what the return looks like. What I am really struggling to do now is just limit the number of items in "selfie_paths". This right now would return every single selfie_path from the database, but I want it to return no more than 5.
I am really struggling to figure out how to do this. Do I need another subquery that replicates the same PostGIS query with a limit set on it? Is there Any way to limit the size of "selfie_paths" in the query as I've made it? Any help would be so appreciated...MrAhmed
02/04/2023, 8:33 AMluke_b
02/04/2023, 10:28 AMuser
and a table notes
. notes
has a column user_id
to enable a foreign key relation to user
.
I've set the foreignkey constraint to on delete cascade
.
So whenever a user gets deleted it should also delete all notes
associated with this user.
So far so good.
Now, I want to enable RLS for both table that only authenticated users can delete entries with their user_id
.
So making an API call to delete an entry from notes
and passing the user_id
works.
However, when I want to make use of on delete cascade and only send a delete request to the user
entry, on delete cascade fails because there's no user_id forwarded.Solemensis
02/04/2023, 10:39 AMXmanu91
02/04/2023, 12:13 PMthis.supabaseService.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: this.getURL()
}
});
anyone know what is the problem ?DisamDev
02/04/2023, 12:25 PM#error=unauthorized_client&error_code=401&error_description=Email+link+is+invalid+or+has+expired
I want to detect if an error occurred in the magic link, so If the url loads with #error=unauthorized_client&error_code=401&error_description=Email+link+is+invalid+or+has+expired
do something.
There's some native module of supabase to do that? Or how can I do this in Next.js?khairulhaaziq
02/04/2023, 12:36 PMSunTzu
02/04/2023, 1:19 PMYourAverageTechBro
02/04/2023, 2:13 PM! Do you even Vim, bro?
02/04/2023, 3:12 PMThomas.
02/04/2023, 5:11 PMgb4de
02/04/2023, 5:17 PMcat
02/04/2023, 5:33 PM"name": "Pobret\u00e3o"
that I want to store to a db table. Should I store it like this or as Pobretão
? I'm going to retrieve it later and show on a website.Lukas.lwz
02/04/2023, 5:57 PMName532
02/04/2023, 6:25 PMPoypoypoy
02/04/2023, 6:35 PMzicxor
02/04/2023, 7:22 PMuser8923
02/04/2023, 7:35 PMmowatt
02/04/2023, 7:49 PMraoxnei
02/04/2023, 8:12 PMculiao
02/04/2023, 8:13 PMkyds3k
02/04/2023, 8:42 PMOsewe
02/04/2023, 8:46 PM