Logo

Supabase Extension which you should know.

PR
Pradeepkumar RaiSenior developer
PUBLISHEDNov 11, 2022
TAGS
supabaseextensions
SHARE

What is Supabase

Supabase is an open source Firebase alternative. Start your project with a Postgres database, Authentication, instant APIs, Edge Functions, Realtime subscriptions, and Storage. With the Postgres database, supabase also provides pretty practical extensions. There are a lot of extensions. Below are the two which I found very helpful.

HTTP RESTful client

RESTful APIs are servers which accept HTTP calls. Using the extension, you can now make http request from the postgres itself The function's available are

  1. http_get()
  2. http_post()
  3. http_put()
  4. http_delete()
  5. http_head()

Here is a example

GET Request:

Select content::json->'quote'
from
http_get('https://api.kanye.rest/);

POST Request:

select
"status", "content"::jsonb
from
  http_post(
    'https://jsonplaceholder.typicode.com/posts',
    '{ "title": "foo", "body": "bar", "userId": 1 }',
    'application/json'
);

You can use PG_JSONSCHEMA extension to translate row value to json while doing post request.

Source - https://github.com/pramsey/pgsql-http

pg_cron

There are certain procedures that need to be done in routine periodically like cleaning out the database, generating analytics, and sending out notifications. We used to use google clouds to create cron jobs triggers. But with the pg_cron extension now we can simply schedule cron jobs from the postgres.

Creating a cron job

select cron.schedule (
'webhook-every-day-at-10-am', -- name of the cron job
'* 10 * * *', -- every day at 10
$$ 
update users u set quote =
(Select content::json->'quote'
from
http_get('https://api.kanye.rest/')) where u.subscrition = true;
$$
);

Deleting a cron job

SELECT cron.unschedule('webhook-every-day-at-10-am');

Source - https://github.com/citusdata/pg_cron

Conclusion:

Supabase is something that solves most of the backend issues. Here at Heisentech, we have been using Supabase for more than a year. And we are quite happy using it. There were some points where we wished to have certain features available which surprisingly got added later. The Supabase team has constantly added more features and support.

HeisentechStay up to date with all Heisentech news
Logo

We believe every owner or business leader knows what is needed to better their business. If you are amongst those people, and want digital tools to get you there, we are here to assist you. If you are not aware of which processes in your business can be transformed, worry not, we will assist you. Either way, let's have a consultation call.

Mumbai, India
Shivdarshan CHS, Bhandup(W), Mumbai - 400078.

©2021 All right reserved. heisentech solutions pvt. ltd.