Alessio ๐ฃ
08/23/2022, 6:39 PMJackTheCoder
08/23/2022, 6:40 PMRelisora
08/23/2022, 7:02 PMORDER BY
table in the params, aswell as if it's ASC
or DESC
.
Overall I found a solution that works pretty well... Except for one special case.
Here is my function (please bear with me, I simplified as much as I could...):
sql
create or replace function test(order_input text default 'wizard_battles', order_direction_input text default 'asc')
returns table (wizard_id int, wizard_battles bigint, wizard_wins bigint, wizard_win_rate numeric)
language plpgsql
as $$
begin
return query
SELECT
wizard_battles.wizard_id,
wizard_battles.wizard_battles,
wizard_battles.wizard_wins,
round(100 - (wizard_battles.wizard_wins::real / wizard_battles.wizard_battles::real * 100::real)::numeric, 2) AS wizard_win_rate
FROM ( SELECT team.wizard_id,
count(*) AS wizard_battles,
count(*) FILTER (WHERE team.is_winner = true) AS wizard_wins
FROM battle
JOIN team ON team.battle_id = battle.id and team.wizard_id <> 'some-id'
inner join "usersOnBattles" ON "usersOnBattles"."battleId" = battle.id
inner join "user" ON "user".id = "usersOnBattles"."usersId"
WHERE "user".id = 'some-uuid'
GROUP BY team.wizard_id) wizard_battles
GROUP BY wizard_battles.wizard_battles, wizard_battles.wizard_wins, wizard_battles.wizard_id
ORDER BY
case when order_direction_input = 'asc' and order_input = 'wizard_win_rate' THEN wizard_win_rate end,
case when order_direction_input = 'desc' and order_input = 'wizard_win_rate' THEN wizard_win_rate end desc;
end;
$$;
I initially had more case when
which all work, I only left the one that doesn't for readability.
Funnily if I extract the query and populate the ORDER BY
with wizard_win_rate
it works!
I tried a lot of things but nothing worked. Anyone has an idea?KamilBartczak
08/23/2022, 7:03 PMjvlobo
08/23/2022, 7:58 PMhankg
08/23/2022, 8:32 PMBloodyaugust
08/23/2022, 8:52 PMsupabase-js
(I'm on 1.36.0-next.29
specifically) to get realtime updates for a specific table. I've enabled realtime on the table, ensured that all replication toggles are on for the supabase_realtime
replication, and enabled my table as a source for that replication.
Here's the relevant client code:
supabase
.channel('*')
.on('postgres_changes', { event: '*', schema: 'public', table: 'posts' }, (payload: any) => {
console.log('Change received!', payload)
})
.subscribe()
I'm in a React/TS app. The behavior that I'm seeing is that no updates are logged. When digging into the websocket messages, I see that the client immediately sends messages with events phx_join, access_token, phx_leave
. All are acked, including with a phx_close
message at the end. It continues to send heartbeats. Did I discover a bug in latest, or am I doing something wrong that causes the client to immediately leave?TypeNull
08/23/2022, 10:41 PMriccardo
08/23/2022, 11:45 PMso
08/24/2022, 12:18 AMjs
// index.js
import { useState, useEffect } from 'react'
import { supabase } from 'utils/supabaseClient'
import Auth from 'components/Auth'
import Account from 'components/Account'
export default function Home() {
const [session, setSession] = useState(null)
useEffect(() => {
supabase.auth.getSession().then(({ data: { session } }) => {
setSession(session)
})
supabase.auth.onAuthStateChange((_event, session) => {
setSession(session)
})
}, [])
return (
<div className="container" style={{ padding: '50px 0 100px 0' }}>
{!session ? <Auth /> : <Account key={session.user.id} session={session} />}
</div>
)
}
js
// Auth.js
...
const { user, session, error } = await supabase?.auth?.signInWithOAuth({
provider: 'discord',
})
...
The Discord API returns a 200 for the following request:
js
https://discord.com/api/v9/oauth2/authorize?client_id={REDACTED}&response_type=code&redirect_uri=https%3A%2F%{REDACTED}.supabase.co%2Fauth%2Fv1%2Fcallback&scope=email%20identify&state={REDACTED}
But the callback returns this error:
js
http://localhost:3000/?error=server_error&error_description=Unable+to+exchange+external+code%3A+dQ9DfLMcgFgjlU2C5VO0nRwHzZu8OM
with payload:
js
{
error: server_error
error_description: Unable to exchange external code: dQ9DfLMcgFgjlU2C5VO0nRwHzZu8OM
}
Nilu
08/24/2022, 12:45 AM0xSmartCrypto
08/24/2022, 6:55 AMSTILLWATER;
08/24/2022, 7:41 AMnexik
08/24/2022, 8:02 AMSTILLWATER;
08/24/2022, 8:23 AMAdrianMsM91 {KBL}
08/24/2022, 9:02 AMscheduledisplay
08/24/2022, 10:07 AMWonday
08/24/2022, 10:09 AMsupabase.auth.api.setAuthCookie
but this seems to only set, not clear the cookie?
so we need to check for that case in supabase.auth.onAuthStateChange
and then call another api route with supabase.auth.api.deleteAuthCookie
?
2. if the login is stored in localstate, the supabase client is just using the anon key? or when and where is the state token passed to the client? is it safe for the session to be stored in localstate?
is it safest just to store the token in client side session and add it to each request ?
3. if i end up having both cookie and local storage, when the page loads, which of the two should take precedence? I would have thought the cookie, but supabase's focus on storage state is making me question this
thanks for any helpers, pointers at guide's, threads or examples, i just couldnt really find anything discussing this. are there clear answers or does this all depend on the app?shtepa
08/24/2022, 11:04 AMconstructor(private readonly supabase: SupabaseService) {}
. What could go wrong? Reason I am asking is that when I use React with Supabase I don't remember using some similar guarding mechanisms so I thought I might be missing something hereandreaselia
08/24/2022, 11:47 AMojg15
08/24/2022, 12:20 PM0xSmartCrypto
08/24/2022, 12:47 PMsupabase start
Docker is running. However, when I call the api
const { data, error } = await supabase
.from('table_name')
.select(`
column1,
column2
`);
I get an error message as such:
{
message: 'FetchError: request to http://supabase_kong_projectname:8000/rest/v1/table_name?select=... failed, reason: getaddrinfo ENOTFOUND supabase_kong_projectname',
details: '',
hint: '',
code: 'ENOTFOUND'
}
Can someone please help?drewbie
08/24/2022, 3:12 PMeq
and neq
filters for the autogenerated Graphql API. eq
and neq
set to a value seems to work. But eq: null
and neq: null
don't appear to be working. Not sure the best to debug this as I am testing it with the local development setup. Here is an example of the query I am trying to perform. A category has a parent_id which references another category. This query returns back nothing while there are in fact entries in the database that don't have a parent_id. Any help is appreciated! Thanks
```
query CategoriesCollection($filter: categoriesFilter) {
categoriesCollection(filter: $filter) {
edges {
node {
name
parent_id
}
}
}
}
{
"filter": {
"parent_id": {
"neq": null
}
}
}Swapnil
08/24/2022, 3:18 PMfefox74
08/24/2022, 3:33 PMNiki
08/24/2022, 3:41 PMtable profiles (user_id uuid, role text)
can I somehow compare the old and the new value in an insert policy?
Example:
sql
create policy "Users can update own profile but cannot change role."
on profiles for update
with check ( auth.uid() = user_id and old.role != new.role);
e.sh
08/24/2022, 4:00 PMDeleted User
08/24/2022, 4:33 PMScores
table of my database. For some reason I get an empty array when logging data
even though I already inserted a row into my table. Am I missing something?
Code:
js
import { supabase } from '$lib/supabaseClient';
async function getScoreList() {
let { data, error } = await supabase
.from('Scores')
.select('*')
console.log(data)
}
getScoreList()
Twisted Chaz
08/24/2022, 4:41 PMalbums_genres.album_id
has a squiggly and the error Argument of type '"album_genres.album_id"' is not assignable to parameter of type 'keyof AlbumGenre'.ts(2345)
const { data: genres, error } = await supabase
.from<AlbumGenre>("genres")
.select("id, genre, album_genres!inner( sub_genre )")
.eq("album_genres.album_id", album_id);
and my current type is
type AlbumGenre = {
id: number;
genre: string;
album_genres?: {
album_id: number;
genre_id: number;
sub_genre: boolean;
}[];
};
bsnow
08/24/2022, 5:18 PM