Transcript for:
Building Real-Time Apps with Superbase

let's talk about real time and with super base we can do real time so what is real time here I got an application that I have created and I'm going to push online okay and in this application you will be able to write messages and here those messages will be like in real time like a chat okay so what I want to do here is to create first a table a new table and this table is going to be called post okay and on this post will be I will have an IDE I created that okay and what I want to do I want to actually have the model of my uh message so here we see that we've got a name so I'm going to add a name and here is going to be a text okay and then I will have a description okay and here it will have a text also so here I want to say it's not going to be nullable for both of them we want to have some content and here we are so I'm going to click on save all right I got my post table but I didn't enable real time here so what I'm going to do I'm going to click on database here I'm going to go uh on uh the table post which is here and I'm going to click here you see we've got enable real time broadcast changes on this table to Auto write subscriber so I'm going to do this I'm going to click on Save and when it's done what I need to do is to go on authentication on policies and I need to add some actually some policies to my table so I'm going to click here on add a new policy I will say that I will enable the read access to everyone and I don't need anything so here I can select the role Anon so I'm going to click on review save policy so everybody will be able to select the post now I want to say that I want that everybody can be um actually a post so I'm going to click here on use template here we are and I'm going to unzoom a little bit and I'm going to remove here authenticated okay I'm going to put Anon and I'm going to click on review so now everybody on the post table will be able to get the messages and to insert them but before we send our message we need to have a look a little bit at the code so what do I have here I have an insert here that actually is in inting the new message that I got up here okay and what I do here I'm pushing the message of course locally if we've got data in return so that's the first thing let's see if we can push messages into our post table okay let's go let's say test test I'm going to click Send I'm going to update and here we are we've got test here and if we look at our database we've got a test down here also so I'm going to delete this row let's say that now what I would like to do is when I put my uh actually my message here I would like to him to appear here so what I can do is to create a second function called Fetch message that we can have down there and call it once I have sent my message that's the first solution and the second solution is of course to subscribe to the table post so here with that code with client. Channel and here we are going to subscribe to a custom channel so here it's going to be the name that I give it can be anything I can say on so channel on progress changes I'm going to subscribe to any event here with the um star on the schema public and on the table post so I'm going to console log my payload here just to see if I got an answer every time I'm going to push a message here it is supposed to answer so I'm back in my app now I'm going to say code with Gom and I'm going to type hello there and I'm going to click on send and look at this I got an answer from my subscribe and I got the message down there so if we look here we've got an answer from the table in real time because we enabled real time before and because we put this code client channel on we are listening we are subscribing down here here to the the table post that we've got here and in real time when there is some changes here we can see that we are notified so what I'm doing here I'm pushing to my message list okay the new message on the payload so this is why I got this message here and if I'm getting back to my application we can see that my message has been recorded if you want to test this realtime functionality on my own database you may go to superbase minus real time. netlify doapp here you can try in real time to post messages and maybe you will see some other people posting messages at the same time