Welcome to Planet No Code
If you're just starting out building a Bubble app then welcome to our channel. We are Planet No Code. We've got hundreds of Bubble tutorial videos for people just like you from beginners all the way through to advanced and you can find them all on our website planetnocode.com. You can find videos there that you can't even find on YouTube, but this is my Beginner's guide to the Bubble database.
Introduction to Bubble
Bubble is a fantastic no code web app creation tool. It really excels at building web apps and I'm going to explain to you some of the key points of understanding how the database works.
Bubble's Interface
In Bubble you've got these tabs down at the left hand side. You've got design, that's where you design your UI, workflows where you create your workflows, and we're going to be focusing in this video on data.
Understanding Data Types
Your data can help to think of this like a series of sheets in Excel or if you are a bit more modern maybe Google sheets. All of my data types represent a sheet. I've got a lot of data types in here because this is an app I keep coming back to and using throughout all of our video demos. If you see anything that you like here do a search on our website because you'll find content all about it such as how to generate AI images.
Creating a Data Type
Creating a data type. Let's do one for this video. I'm going to say let's create a type called book and Bubble supplies some built-in fields such as who created it, when it was created, when it was modified and a slug. The slug is part of the URL if you were to link to a page all about this particular book. The keyword there to look up in our library is type of content. Then you can set the slug or like the slash Harry Potter would be one way of setting the slug for a Harry Potter book.
Adding Fields to Data Types
We can then go ahead and add in extra fields. A book is definitely going to have a title and the title I'm going to set as Text. A book is also going to have an author and so I might want to have an author Data type in my database. That way I find it really easy to display books by Author so let me add in an author data type and the author is going to have a name.
Creating Relationships Between Data Types
Now I want a way of saving author into a book. So I go back to my book and I create a field and I can create a field called author. Some books have got more than one author. So actually I can say this field is a list and that allows me to list more than one author into the book's author field.
Adding Data to the Database
Let's put some data in that and give it a go. So I'm going to go into books and let's create a book here. I got to think of a book off the top of my head. Okay, we will just go with Harry Potter. We create a book and that adds an entry into our database.
Understanding Development vs Live Versions
It's important to recognize that this has a live effect on my Preview or my development app. Your Bubble app has at least two separate databases: your dev version, this is where I'm making all these edits creating all of these extra data types, and your live version. They are completely separate. This has created an entry in my books Database for Harry Potter, but it's not going to appear in my live app's database.
Setting Up Primary Fields
Now I want to set an author for Harry Potter. So I go into authors and I can add in JK Rowling. I think I've spelled that right. Then I can go back into books and Edit and I want to add in JK Rowling but I'm not seeing JK Rowling in this selection and that's because I need to set the field for me as a human to view the readable data. What I mean is that every entry in your Bubble database has a unique ID just like this. But how do I know which unique ID that represents? Well, I need to tell Bubble to put a text label there instead and I can do that with primary fields.
Understanding Database Relationships
So I find author and I say use the name field. Now if I go back in I can go JK Rowling and I get JK Rowling and I have to click add. This is because it's a list and I can click save. Now it has added that entry. It's created a database relationship between those two entries. If I go back onto author, the author does not have in and of itself a link back to Harry Potter. It is Harry Potter that has a link through to JK Rowling.
The Importance of Privacy Rules
One more thing because it's so important and you don't believe how easy it is to miss is privacy rules. Imagine you've created an app for your users where they've got their own personal library. But it should only be accessible to them. At the moment any book and any author is completely publicly visible. Just like a blog post in fact someone with the right tool set could basically scrape all the data from my Bubble app about all my books and all my authors.
Setting Up Privacy Rules
But what if I want to make it so that if a user creates a book only they can see it? On books I would uncheck all of these "everyone else" fields because I want it to be private. Then I can say something like current user. It doesn't matter which around you do this other thing we can say this book's creator is Current user and like 90% of the time that is the appropriate privacy Rules expression, but obviously it depends on your app. If your app has got an organization feature or a team feature, you're going to need to find the way of sharing data across multiple users, but restricting it to the particular team or organization.
Conclusion
That is my beginners guide to the Bubble database. If you've got any questions leave a comment down below. We love responding to them. We also love sharing our pre-existing videos. Like I say we've got hundreds of them so ask a question, good chance we've already got a video and we can send you a link to watch it right away.