was wondering what would be the best way to implem...
# help
s
was wondering what would be the best way to implement a webhook type of system when a row gets inserted? e.g. new row is added to profile, I now want to call code to send an email about this new profile to an admin user
n
Hello @samjmck! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
t
Postgres Triggers are great for performing actions on inserts, updates and deletes. You could create an Function / RPC that sends a http request to your fav transactional email api such as mailgun / postmark app.
n
samjmck (2022-05-08)
s
seems fairly unusual to make an http request through sql?
just looked at function hooks and that seems more fitting
t
you might be right I'm not up-to date with all supabase though there is a postgres extension that allows
http
that you can install.
s
also, would a postgres trigger be the best way to eg automatically create a new profile row when a user signs up?
t
I think so.
s
alright
g
With function hooks you have to currently take the format from the row as it sends it. So you need an external function to take that and extract the data to send to your email provider. Soon they should add the hook for an SB edge function though. You can also use pgsql_http or maybe even pg_net (SB's asynch version which hooks uses).
s
couldn't you use that in combination with a deno deploy function?
or is that what you mean with hook for an SB edge function
g
yes
s
but is it right to say that calling http requests through postgres in an sql query isnt* the most efficient way to do things
isnt*
especially because its going to be blocking no?
g
If you can get pg_net (it is async) to work for you, then that is more efficient as you don't need to have the extra delay of the edge function and you used the pg_net in the hook anyway. But the http function is sync as is blocking so not as nice.
s
hmm
alright
just feels so hacky unfortunately
g
Then use a hook to a deno or edge function, you just asked for most efficient. I do my email in an edge function.
s
alright
thanks for the help
g
SB edge functions though currently block mailer IO ports. My provider has an api so I was able to use that method.
s
i think i will end up using cloudflare workers anyway
g
Using a function for me was better as I sometime call it directly from the client so database is not involved at all.
s
that's also possible
n
Thread was archived by @samjmck. Anyone can send a message to unarchive it.