https://supabase.com/ logo
#off-topic
Title
# off-topic
b

bluetoothfx

03/20/2022, 12:22 PM
Is it possible to execute raw/custom query in supabase with some parameter? e.g: select * from books where cid=1;
g

garyaustin

03/20/2022, 1:52 PM
If you mean from the API, then rpc call with a postgres function is the only way.
b

bluetoothfx

03/20/2022, 3:22 PM
Can i pass params?
g

garyaustin

03/20/2022, 3:26 PM
Yes. const { data, error } = await supabase .rpc('echo_city', { name: 'The Shire' })
Strings, numbers, arrays, json... multiple parameters...
b

bluetoothfx

03/20/2022, 3:34 PM
Could you point some documentation?
d

debabrata

03/20/2022, 4:54 PM
Another possibile way is connecting to your postgres db directly from your server and running queries without using Supabase's library
b

bluetoothfx

03/20/2022, 5:51 PM
I need to pass data between client and server. How would that be possible?
Could you explain more on it?
d

debabrata

03/20/2022, 5:59 PM
I needed to run some custom SQL queries in a next.js project so here's what I did: Set up an API route
api/account/
let's say to fetch account details from the db. Since functions in api routes run on the server I could use normal node.js code. There are multiple libraries which you can use to connect to your postgres db and run queries (I don't remember which one I used unfortunately) For passing data between client and server... Let's say I want to fetch the account details for account id 123. I can make a post request at my
/api/account
endpoint and pass the account id in the body of the request. I can access this from the request object the server receives. Then I can run the required query and return the data back to the client in the response
Does this help?
b

bluetoothfx

03/20/2022, 6:15 PM
@User in terms of security and managing you need to make/take some extra layer which defeats the purpose of serverless. But yes I agree this could be one another way. (But if this is open then any client might make call and increase your traffic in the server.) 😉 Thanks a lot guys.
d

debabrata

03/20/2022, 6:23 PM
You're welcome. Yes this is just another option. Weigh the pros and cons and go with whichever one feels right 🙌
n

Needle

03/20/2022, 10:02 PM
Thread was archived by @bluetoothfx. Anyone can send a message to unarchive it.