Konstantin Trunin
03/21/2023, 6:37 PMsiva m
03/21/2023, 6:45 PMhortinstein
03/21/2023, 7:13 PMcreate table phone_calls (
id uuid default uuid_generate_v4() primary key,
owner_id uuid not null references auth.users(id) default auth.uid(),
phone_number in,
coord text,
created_at timestamp default now()
);
and I wanted to query with a list of phone numbers and return only the most recent record for each phone number.
I know I could do this by running a query for each phone number, but is it possible to only get the most recent for each in the list with a starter query like this?
final data = await supabase
.from('phone_calls')
.select('id,coord')
.in_('phone_number', ['4257771111', '4257771112']);
I know I could parse them out after it returns, but I dont want to return all that data if not necessary and would be afraid it could grow past what I would reasonably think the client would handel.Tehker
03/21/2023, 7:54 PMhomyak
03/21/2023, 8:02 PMsupabase
to delete the item as per the docs, the item is successfully deleted but it returns an error object. I am instantiating supabase
via createServerComponentSupabaseClient
from the @supabase/auth-helpers-nextjs
library.
json
{
message: 'FetchError: Response constructor: Invalid response status code 204',
details: '',
hint: '',
code: ''
}
javascript
const id = '9c16f914-8695-4dc5-b37e-bb54a45d32a8'
const supabase = createClient()
const { error } = await supabase.from('topics').delete().eq('id', id)
if (error) {
console.warn('[Error]', error)
}
Joseph96
03/21/2023, 8:12 PMonAuthStateChange
to work across tabs. Right now the docs say this.
Currently, onAuthStateChange() does not work across tabs. For instance, in the case of a password reset flow, the original tab which requested for the password reset link will not receive the SIGNED_IN and PASSWORD_RECOVERY event when the user clicks on the link.
This was important to me when working with a Expo-React-Native App I was working on when authentication happened when opening an in-app browser. I figured out a work around in the end. But, would be nice not to have a work around.
Thanks!Psygen
03/21/2023, 8:36 PMRK
03/21/2023, 8:44 PMGrimmjoww231
03/21/2023, 9:49 PMyayza_
03/21/2023, 10:32 PMhttps://i.imgur.com/iPKndRn.png▾
js
const selectQueryString = `
*,
category:categories(id,name),
product_skus(*, sku_attribute_values(sav_id:id, attribute_values(value), attributes(name)))
`;
js
sku_attribute_values: [
{
sav_id: 146,
attribute_values: { value: '12oz' },
attributes: { name: 'Size' }
},
{
sav_id: 147,
attribute_values: { value: 'Strawberry' },
attributes: { name: 'Flavor' }
}
]
but I was wondering how I can query this to get the data I need like this:
js
attributes: [
{
sav_id: 146,
value: '12oz',
name: 'Size'
},
{
sav_id: 147,
value: 'Strawberry',
name: 'Flavor'
}
]
I tried to do it the other way around where I query attributes first, but then I get a relationship error and any of the hints provided in the error give me a many to many or one to many results (and i'm not very good on using hints)
Would be nice to do it in in the supabase client but if I have to map through them in js that's fine, just wondering if i'm missing something i'm not aware of with the clientmansedan
03/21/2023, 11:06 PMsql
CREATE OR REPLACE FUNCTION test_pool(date_val DATE, type_val VARCHAR)
RETURNS TABLE (profile UUID, win_percentage NUMERIC, unit_profitability NUMERIC) AS $$
DECLARE
total_units_won NUMERIC;
total_units_lost NUMERIC;
BEGIN
IF type_val = 'win_percentage' THEN
RETURN QUERY
SELECT p.author AS profile,
(CAST(COUNT(CASE WHEN p.pick_status = 'WIN' THEN 1 END) AS NUMERIC)
/ NULLIF(COUNT(CASE WHEN p.pick_status <> 'pending' THEN 1 END), 0))
* 100 AS win_percentage,
0 AS unit_profitability
FROM posts p
WHERE p.created_at BETWEEN date_val AND NOW()
GROUP BY p.author
ORDER BY win_percentage DESC;
ELSIF type_val = 'unit_profitability' THEN
RETURN QUERY
SELECT p.author AS profile,
0 AS win_percentage,
COALESCE(SUM(CASE WHEN p.pick_status = 'WIN' THEN p.units_win ELSE 0 END), 0)
- COALESCE(SUM(CASE WHEN p.pick_status = 'LOSS' THEN p.units_risked ELSE 0 END), 0)
AS unit_profitability
FROM posts p
WHERE p.created_at BETWEEN date_val AND NOW()
GROUP BY p.author
ORDER BY unit_profitability DESC;
ELSE
RAISE EXCEPTION 'Invalid type value: %', type_val;
END IF;
END;
$$
LANGUAGE plpgsql;
When running the queries individually, outside of this function, we get results like the attached screenshots. Can anyone sport what might be incorrect about our RETURNS TABLE statement?Adobe.Flash
03/21/2023, 11:20 PMcreate_index
function programatically.
Thank you.samuyoon195
03/22/2023, 2:45 AMmlc
03/22/2023, 3:28 AMinfinity
03/22/2023, 5:15 AMharshcut
03/22/2023, 5:26 AMSumit1993
03/22/2023, 8:10 AMshriharip
03/22/2023, 9:04 AMsupabaseUrl, supabaseAnonKey'
. The relevant git issue with more code https://github.com/supabase/auth-helpers/issues/476
ThanksHan
03/22/2023, 9:11 AMmaks_k
03/22/2023, 9:52 AMkobyisalegend
03/22/2023, 10:13 AMAccess to fetch at 'http://localhost:54324/auth/v1/token?grant_type=password' from origin 'https://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
And I really can't get my head around that, I don't find any documentation or help to get my request get trough on local development.
If I use the DB directly from a supabase URL, f.ex.: https://xxx.supabase.co
it works just fine. But i really want to operate directly on a local environment and not use the web application for my app at the moment.
The request I make for example, to login is like that:
supabase.auth.signInWithPassword({
email: 'email@xyz.dev',
password: 'xyz1234',
})
Can somebody tell me what I do wrong here?MusashiGarami
03/22/2023, 11:00 AMfiliphric
03/22/2023, 11:03 AMts
// eslint-disable-next-line @typescript-eslint/no-var-requires
const stripe = require('stripe')(process.env.STRIPE_API_KEY)
export default async (req: any, res: any) => {
if (req.query.API_ROUTE_SECRET !== process.env.API_ROUTE_SECRET) {
return res.status(401).send('You are not authorized to create a new user')
}
const customer = await stripe.customers.create({
email: req.body.record.email
})
await supabase.from('profile').update({
stripe_customer: customer.id
}).eq('id', req.body.record.id)
return res.send({ messgae: `stripe customer created hello ${customer.id}` })
}
I have created an ngrok tunnel (as tutorial suggests) and set up a webhook on supabase.
the webhook seems to trigger properly as confirmed by couple of console logs.
The odd thing is, that after the stripe.customers.create
function runs, nothing else in the function above gets executed, again, tested by adding a bunch of console logs.
when I call the api locally, both localhost and ngrok urls work fine and will add will properly update the profile
table.
maybe this is more of a js/ts question, but I’ve been trying to figure this out and could not find a doc or a resource that would guide me.
any help appreciated.Trevvy
03/22/2023, 11:20 AMMuezz
03/22/2023, 12:14 PMauth.uid()
?Computer
03/22/2023, 2:14 PMSaad
03/22/2023, 2:25 PMhidfap
03/22/2023, 2:35 PMimport 'xhr_polyfill'
import { serve } from 'std/server'
import { CreateCompletionRequest } from 'openai'
serve(async req => {
if (req.method === 'OPTIONS') {
return new Response('ok', {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers':
'authorization, x-client-info, apikey, content-type'
}
})
}
const { query } = await req.json()
const completionConfig: CreateCompletionRequest = {
model: 'text-davinci-003',
prompt: query,
max_tokens: 256,
temperature: 0,
stream: true
}
return fetch('https://api.openai.com/v1/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${Deno.env.get('OPENAI_API_KEY')}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(completionConfig)
})
})
these edge functions return a RedableStream fetch from openai
my problem is that when i run the function once I cant run it again the second function is blocked until the first one is not completed
how can i get two edge functions to work in parallel ?
thanks for your time & work ❤️Sumit1993
03/22/2023, 2:56 PMLuke
03/22/2023, 3:26 PM