‫Hello, my friends, and welcome back.
‫In this video, we will start learning how to deal with real time databases.
‫So we will learn how to write data and receive data from real time databases.
‫From the console Firebase console Under the Fire Kotlin.
‫This is the project that we have created.
‫You can select from the left side build.
‫You can get the authentication app, check Firestore real time databases release like Crashlytics Performance
‫Analytics and engage.
‫From this I need to start with the real time database.
‫So click on Realtime database and here you will get the real time database panel.
‫I will click on Create Database, select the server, and I will start in test mode.
‫You can modify these rules later on, but I will click enable and it will be opened for one month from
‫now.
‫And here we go.
‫Congratulations, guys.
‫You have created your first real time database.
‫You can check from here the data.
‫This is the data and the database.
‫The rules.
‫You can modify the rules.
‫Read.
‫You can.
‫You can set it to false to to prevent any read.
‫You can set the write to false.
‫You prevent any write to the database and the backups.
‫You can save daily backups usage.
‫You can see the usage and the usage statistics.
‫But we are interesting in adding data here.
‫So please guys, look here.
‫At Fire cutting.
‫This is the name of our project and these are randomly generated things.
‫Dot Firebase, dot IO or io.com.
‫This is the link.
‫This is the reference to our databases How to allow Android studio to know this reference.
‫But first we need to add the dependency for real time database product from fires base.
‫I told you that in the in granule file we need to add the services that you need here.
‫From the Firebase.
‫I will go to the documentations, the fundamentals, or you can go to the go to console and you can
‫see the documentations.
‫You can select build.
‫Or from here build, you can select a real time database and choose Android.
‫Get started.
‫You will scroll down to get this implementation.
‫I will paste it here again.
‫There is no need to specify the version of Android Firebase.
‫When using the click on sync now.
‫And this dependency is for real.
‫Time.
‫Data base.
‫Okay, now we can.
‫Use the firebase.
‫Real time database in our application.
‫You can also deep dive into these documentations I will start with.
‫Writing data to the database.
‫First of all, you need the reference.
‫So in order to get the reference, you need to specify an object from Firebase database dot get instance
‫and get the reference from it.
‫How to do that?
‫You can see.
‫Here.
‫We can make like this or we can write them at one one line.
‫But I will show you here.
‫So I can select from the left, read and right.
‫You can go down and you see this note to read or write data from Firebase Database.
‫You need an instance of database reference.
‫You can select Java or Kotlin, but since we are getting.
‫Firebase connected to Kotlin.
‫We need to use the Kotlin private late and database and Alt+ enter to import this from Firebase database
‫package.
‫Then I need to copy this reference.
‫Down.
‫Real time database reference.
‫Okay, so this is the reference of Firebase.
‫Enter Alt+ enter to import the packages.
‫Here we are specifying the reference to our database that this is here because it knows from the Json
‫file that we have created before.
‫So I will copy this in order to inform you that this is the reference for our database.
‫Okay.
‫This is the reference and here how we get connecting with the database on Firebase.
‫To write data to Firebase for basic operations.
‫You can use set value method to save data to specified reference, replacing any existing data at the
‫path.
‫You can use the method to pass types that correspond to available Json types like string long double
‫boolean map list, or you can pass custom Java objects.
‫In this video we're going to pass simple data.
‫Simple, primitive data.
‫And later on we need to learn about how to save and pass and write.
‫Also read custom Java objects that we have created in Android studio.
‫So to get the reference and start writing data.
‫I will.
‫Start with writing data.
‫Do.
‫Firebase.
‫I will use the reference.
‫Always start with the reference dot.
‫Her get or Here I have.
‫I'm having the reference dot child.
‫What is the child in Firebase there?
‫The the mechanism and the saving mechanism and the dealing with the firebase real time databases are
‫done by.
‫Key value pairs.
‫So exactly like like maps, firebase stores, key values.
‫So I specify the child.
‫I will put value inside it.
‫So whenever you specify the child, you can get the value.
‫Give me the key.
‫I'll give you the value.
‫This is how Firebase work.
‫The child.
‫I will name it as gold price, for example.
‫Or price.
‫And.
‫I will set the value.
‫This is the method that I was talking about and I will set it like 100 or $1920.
‫Okay, now let's run our application and open our Firebase realtime database.
‫Okay.
‫Let's run it.
‫Without.
‫Here we need to specify not assigning report.
‫You need to specify the application.
‫Click run and wait for the emulator to come online.
‫And here we go.
‫Once the application is starting.
‫The Firebase will create a real time database.
‫You can see the the.
‫How fast is Firebase Price?
‫This is the key.
‫This is the child.
‫And this is the value $1,920.
‫I will update this and I will set it to 41,940.
‫Click run and watch.
‫Guys, how fast is Firebase?
‫Okay.
‫You can see, guys.
‫Once the application is created, the price is updated with the new value.
‫1940.
‫So this is one of things and products and amazing products that.