What is Supabase: realtime cloud database explainer

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Around the middle of 2020 Supabase an open source project released in alpha, it promised to be an alternative to Google's Firebase. And while the through line between the two products is similar, for example, they both provide ways to easily access data. The underlying technology is different Supabase offers a real time PostgreSQL cloud database, and it built on top of a whole host of other services. But what is a real time PostgreSQL cloud database? And why would you want to use Supabase in a project?Well, let's tackle the first question. If you haven't had a real time cloud database, I think about it like the world's friendliest bank. It's a bank that you love going in, there's really no lines, there's no inconveniences, it's like you're the one and only customer. Now let's say you want to open an account with the bank, you walk up to the branch and give them some money to open the account with and in return, that bank gives you a debit card that you can access your funds wherever you are. But you can only access the money you have. So no borrowing. You can withdraw money, use the card to pay for purchases, like food or at the shops. And you can also deposit cash through an ATM. Both of these actions change the amount of money you have in your account. And finally, the world's friendliest bank also offers a service to send you a message anytime there's a large or a suspicious expense. Now, I know I probably explained something that you're all very familiar with. But real time cloud databases work similar to this, instead of a bank, you have a cloud provider like Supabase, and you can give your data to that provided through a CSV import, for example. And Supabase will provide you API's to access and manipulate that data in your application. Adding in real time means that you can subscribe to events that happen in your database. In other words, you're not asking the database for the newest information, it's telling you. It's like the bank giving you a message every time there's a large expense, rather than you having to open up the statement every month to check what expenses are there. Now that we have a high level overview of real time cloud database, let's add in Postgres or PostgreSQL. Now, Supabase is different to Firebase in the fact that it uses Postgres as its underlying database technology. And there's so many reasons why you might choose Postgres, which is a SQL database, versus Firebase, which is a new SQL database. And yeah, there's, there's pros and cons of both. And there's trade offs of both. But one of the reasons that I really like a SQL database is the structure and the type definitions that I can get inside the database itself. What does this actually mean? Let's come back to the world's friendliest bank, they can now store multiple currencies for you. And they'll do so without complaint and fees, as long as there's like a handshake agreement. So you tell them what currencies you want to store, and they'll store it for you. Now, this is similar to a SQL database where you where you have to define the structure and the types of the data upfront, and prevents you from doing something like storing a string value into an integer column. If you try and do this in Postgres, it will complain to you. And that's not the case with Firebase or with a no SQL database. Generally speaking, with a no SQL database, you have to do all of these type checks in your application layer. So imagine if the world's friendliest bank didn't have a handshake to store currencies. So you can give it some US dollars and declare it as pounds. And it would just say yes, and take it. Next time you draw some pounds, it will be US dollars. And that's probably not what you want. Now, let's talk a little bit more about Supabase to get things like real time and API's over a Postgres database, Supabase pulls in other services, like all of these. So I find it really impressive how they stitch everything together to create a pretty seamless experience. For example, Supabase uses Postgres, that's REST, to create a REST API on top of that Postgres database. So that's kind of building the API layer. And then Realtime is a Phoenix web app that uses WebSockets to listen to database events. And yes, Realtime, the project gives you a real time functionality. What can I say? programmers are pretty literal. So what can we build with Supabase? Well, as a small side project, I've built a passphrase generator app that will take a randomly generated number and query my Supabase database to retrieve the corresponding word. So here, I generate aptly spokesman untaxed, and you can see what the data returns if I use postman, to make calls to my database. So as you can see a if I call this REST API, I get a list of words from the word table. So that has a dice roll, which is an integer, and then a word column, which contains a set of strings. And then in this URL, I can also pass in a parameter, dice roll equals this number, and that should return abdomen. And it does know I'm using Postman to do this. But Supabase has a JavaScript client that you can use to make the corresponding calls to your application. If you open up the API docs in Supabase, I can get code snippets that I can copy and paste to get up and running fast. Honestly, these API Doc's are my favourite part about Supabase. Not only do they have these code snippets, they're also auto generating. So that means that any changes I make to my database will automatically get reflected in the docs. Let's try this out. If I have a look at my documentation, I have a test table that has a Boolean field name test and just an ID field. So let's go in and modify this table. So in this table, I'm going to add a new column, I'm just going to call it like URL. And then we'll make this a VAR char because you know presumably will take in a URL string. And then I can save this column and go back to my documentation. And again, going to test table I can see that URL actually exists in this documentation, like it automatically generated for me, which I think is super neat. And while we are here, let's check out the Supabase dashboard. So I can pop into SQL, this tab here and I can run some SQL queries on my database. And then I can also hop over to authentication. And this is where I would handle any potential user authentication, I can also create policies. So I have a word policy or a read only policy on my word table in the database. And then finally, if I check out just test project, there's also this option to add storage. And this feature came in March 2021. It's still in alpha right now. But as you can see, we have buckets that you can create. And you can store folders or files in these buckets. So having images bucket and I can open up some images, and it shows a preview, also previews GIFs, which is awesome. And then videos, it also previews video. So bunch of objects that you can store there. And what I think is kind of cool is in the SQL query, I can actually run a query on my storage bucket, and actually return the metadata for all of those images and videos I have stored on there. And finally, if you're not sure where Supabase could be used in a project, there's a bunch of examples and resources in the docs. You see, there's a bunch of Auth examples, there's a like next js, slack clone, and a bunch of libraries and guides for you to actually go ahead and use Supabase. So plenty of stuff to get your hands dirty with it, definitely give Supabase a try in your next side project. I've used it in a couple of months, and I really enjoy it. It's also free on the hobby teir and I love free stuff. But it also means that the barrier to entry is super low, you just create an account and get something up and running pretty quickly. And there also adding new features as well. So Functions is coming up pretty soon. So that's something similar to like Netlify functions, where you can run server side code in Supabase. And that should open up a whole host of other avenues to explore and functionality that you can lean on. And that's really all I had for this video. I also, at the start of the video give a pretty high level overview of a real time PostgreSQL cloud database. So if there's anything that you want to dive into, please leave a comment down below. See you in the next video.
Info
Channel: Jonathan Yeong
Views: 906
Rating: 4.9230771 out of 5
Keywords:
Id: 1F240hR7nHU
Channel Id: undefined
Length: 8min 13sec (493 seconds)
Published: Fri May 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.