Is it possible to execute raw/custom query in supa...
# off-topic
b
Is it possible to execute raw/custom query in supabase with some parameter? e.g: select * from books where cid=1;
g
If you mean from the API, then rpc call with a postgres function is the only way.
b
Can i pass params?
g
Yes. const { data, error } = await supabase .rpc('echo_city', { name: 'The Shire' })
Strings, numbers, arrays, json... multiple parameters...
b
Could you point some documentation?
d
Another possibile way is connecting to your postgres db directly from your server and running queries without using Supabase's library
b
I need to pass data between client and server. How would that be possible?
Could you explain more on it?
d
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
@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
You're welcome. Yes this is just another option. Weigh the pros and cons and go with whichever one feels right 🙌
n
Thread was archived by @bluetoothfx. Anyone can send a message to unarchive it.