ROOM Database - #1 Create Database Schema | Android Studio Tutorial
🏆 My Online Courses
⭐Discount Coupon: LAUNCH-STEVDZA-SAN
stevdza-san.com
🐱👤 Wanna become a member? Join!
/ @stevdzasan
📸 Instagram
/ stevdza_san
Hello there and welcome to my Tutorial Series. With this video I'm starting a new tutorial series about ROOM database with Kotlin. This tutorial serie will have 5 videos.This current video will be all about creating a Database schema for our project. So if you watched my earlier tutorial series about SQLite Database, then you noticed how hard is it to create and manage one database. But with ROOM library everything is easier! ROOM library is built on top of SQliteOpenHelper class.
Project File (Part 1): drive.google.com/file/d/18CGd...
Room Database Part 2 - Insert Data - • ROOM Database - #2 Ins...
Room Database Part 3 - Read Data - • ROOM Database - #3 Rea...
Room Database Part 4 - Update Data - • ROOM Database - #4 Upd...
Room Database Part 5 - Delete Data - • ROOM Database - #5 Del...
Dependencies:
// Navigation Component
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
// Room components
implementation "androidx.room:room-runtime:2.2.5"
kapt "androidx.room:room-compiler:2.2.5"
implementation "androidx.room:room-ktx:2.2.5"
androidTestImplementation "androidx.room:room-testing:2.2.5"
// Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
// Kotlin components
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5"
Timestamps:
0:00 - Introduction
0:39 - ROOM Advantages
1:09 - ROOM Main Components
2:00 - App Preview
2:38 - Dependencies
3:28 - Create Entity
5:07 - Create Dao
7:02 - Create Database
10:49 - Create Repository
12:10 - Create ViewModel
Пікірлер: 210
It's great to learn from you. I'm glad you're taking your time and putting a good effort into this. So far you are one of the best I've found.
I watched SO MANY Room "beginner" videos that didn't bother to explain anything. Your video is the first one where I feel like I'm actually being taught how to use Room rather than being told what to type. Thank you SO much. I'm subscribed.
I like how you take your time to explain what the various keywords and syntax means. Thank you so much
I started building my database by your tutorial. I think it is smooth according to your soft instructions. I like the way you teach.
imo this is the best instructor for kotlin programming. Thank u so much for sharing your knowledge!
Best tutorial ever found to learn about room database. Thanks for your efforts.
Amazing tutorial!! Straight to the point cleared my all my doubts
Your content is terrific - everything is clear, short, relevant examples and most importantly nothing superfluous. Recently I found your channel and subscribed because it's hard to find good material. Thank you for your tutorials!
@StevdzaSan
2 жыл бұрын
I'm glad I can help 💜
@Tridez99
Жыл бұрын
if you liked his content why did u say that it's terrific? wtf
@ppersik
Жыл бұрын
@@Tridez99 i didn't mean terrific is horrible. It's also mean amazing
Thank you for this tutorial. This clarified few things about MVVM architecture too.
Man you're the best , Keep goin' !
unbelievably good content mate !!! You explain things so efficiently.
@StevdzaSan
3 жыл бұрын
Thank you buddy, I'm glad to help!
You are a gem to kotlin community keep up the good work!!!
Thank you. Really helpful.👌 Waiting for next video in the series.
Loved new video format man Dont CHANGE IT IT LOOKS GREAT
the best way to understand roomdatabase, thanks and keep go on
with love from Ukraine, great job, thank you, thanks to you, I finally understood how to work with Room
Thank you for this tutorial series. Very helpful!
the best instructor on whole youtube
very good video, it helped me a lot. greetings from Mexico....... you already have one more subscriber!
I am very happy get very much knowledge about room database in this video. Thanks bro for the tutorial
Your tutorial is really good. Thanks for share with us.
any update on the dependencies? they look different now
Great video. I respect the effort.
wtf dude, i love the way u speak!! thanks btw
Why did you not check whether the INSTANCE field initialized on line 15 is null or not in the synchronized code block in UserDatabase class at 10:00?
Why is it necessary to initialize the database with the init code block every time UserViewmodel is called?
your tutorial is great it's really help me to understand room lib but may you explain why you used coroutines when you insert data only ?
Hey there I'm creating a chat app and I'm storing the chat messages of each person when I click on them but once I have created a room db it is storing the chat messages of all of them . the thing I need is whenever I click one of my friends chat button a specific room db for them has to open which contains only the chat messages of them and mine. Pls help me to solve this.
Thanks for this sir. Very useful
great very simplified tutorial
Excellent video!
Do you have a tutorial that connects an app with a relational database like mysql?
thankyou !! Really merci
Why did you return tempInstance at 9:35 , and not INSTANCE? Same question for return instance, below that Because of @Volatile or you just like it that way?
Teacher, perfect class! I would like a professional opinion from you on the database. For a large app (Airbnb or Uber), using Room for local persistence may be better suited than pure SQLite, right? I ask this because I have no problems writing code using the SQL language. Thank you for your tutorials!
very nice explanation sir...Very usefull video.
Do I have to create tempInstance variable within getInstance function? what happens if I directly use INSTANCE?
Why do we need compile options since we are working with kotlin and not java?
Thank you too Bro Keep Going! ✊✊✊
fucking best teacher that ever found on KZread.
what a great tutorial
Hey man, I really enjoy your video's. Short and concise. But I have a question about reading data from the database. What if I want to read one row and pass the ID into the function. Do I still have to use a coroutine? If yes, how do I return it in the viewmodel method? Or is it OK to not use coroutines when only reading data from the database? Thank you
but in the UserDatabase, if two or more threads invoke getDatabase at the same time, and then they check that tempInstance is null, they all will run synchronized block, in some order, one by one, creating many database instances? Or not?
that's great !
Could not find method kapt() for arguments ?
are there any prerequisites for this series?
Can you please add a touterial on how sync the database with database on ☁️
Will we repeat the same processing for a second table?
Dear sir, Greetings of the day! I want to create an app which can extract data from excel, csv, xlsx formats and save into android sqlite database and then plot it in Mpandroid chart. If you could help me , please prepare series on it, in kotlin. Searched on youtube but couldn't find good tutorial Thanks in advance
still cant understand why do we creating userDao() func in our DB and returning userDao.. What does it mean to return userDao? Is it object of interface?
How if i want to populate all data into sqlite, like dictionary app ?
Steva-San Hi, would be interesting to use or consume a GraphQL API in android kotlin
This tutorial is more valuable than google guides
@StevdzaSan
2 жыл бұрын
Thanks 😎
Sir i cant wait for the rest of the videos drop it now thanks
Hey. Thanks. What is ORDER BY id ASC for? In the Dao getalldata function
@StevdzaSan
3 жыл бұрын
Sort and get the list in ascending order.
I hope that you will make a tutorial that using mvvm architecture
Hello sir, I have implemented exactly the way you taught. Now I want to add a searchview for this recyclerview with Room data. Do you have any idea how can i do it?
@VeeraSrivastava
3 жыл бұрын
Use Query and display your data
do you record code and then add voice??
Thanks a lot
hello sir can we store list of images in room data base i am unable to do it......
Can we make and manage Room Database in Java too.?
Thank you.
Is there a tutorial on how to do this in Java?
Best
val instance = Room.databaseBuilder( context.applicationContext, userDatabase::class.java, "user name" ).build() i got error this part it said Type parameter bound for T in fun databaseBuilder ( context: Context, klass: Class, name: String ) : RoomDatabase.Builder is not satisfied: inferred type userDatabase! is not a subtype of RoomDatabase!
Really nice explanation of information. I am waiting for next videos on this series. Thanks for these cool videos.
i got an error on Dependencies in line 57 were "kapt "androidx.room:room-compiler:2.3.0""
#9:36 shouldn't the lock cover Al the function? You can see the problem if you watch again.
Thank you , please make videos on mirrorfly & sinch dependcy
Awesome
Loved the video, very simple yet detailed. since you have mentioned Clean Architecture , is there any proper tutorial available ?
@StevdzaSan
3 жыл бұрын
You have my courses on Udemy and Skillshare.
Hello, thanks for the tutorial. I would like to ask in 11:09, why the `database` folder does not exist in data > data > com.example. ?
@marcscherzer
3 жыл бұрын
Never mind, somehow I needed to stop and then restart the Android Emulator. Thanks. EDIT: I have no idea if I needed to set exportSchema = true in UserDatabase.kt. However, here are what I did : (1) set exportSchema = true in UserDatabase.kt (2) stop the Android Emulator (3) start the Android Emulator (4) open Device File Manager. Search for data > data > com.example. > database. Finally the database folder was displayed. Please correct me if I am wrong, thank for the amazing tutorial Stevdza-san.
thank you
So if we have multiple entities / tables, do we need a Dao, Repository, and ViewModel for each?
@marijocarbajal6968
3 жыл бұрын
i think so
this works as well when using Java ?
is there any room series for java
That escaleted quickly! Nevertheless great introduction on ROOM.
Thank you Thank you Thank you
thanks for the video, i have a question. i read some article that said, we dont need to determine room/retrofit run in background, because the library itself will do by themselve. So in this case we don't need set Dispatcher.IO for insert. what's your opinion ?
@StevdzaSan
2 жыл бұрын
I think that you don't actually need to specify IO dispatcher explicitly, because newer version of ROOM database is using it by default. However I'm always specifying it, because it cannot do any harm either way.
@tokosuburselalu8689
2 жыл бұрын
@@StevdzaSan thanks for ur explanation 👍
well video lesson thanks
sir why my code always error and they said value null on entity?
How would I join two tables and retrieve data?
Can you please make a video on how to export a database as csv or txt file?🙏
i get this when i try to access your google play store link : We're sorry, the requested URL was not found on this server.
GL bro
Dear, Can you please tell me why minimumSDK should be 26.
I can't open the grade in the drive
Why we make UserDao as interface . I know interface but i dont know pratical implementation of interface
Having difficulties, the project files are not complete... can you update the download link
I'm try to code follow your video, but when i click on floatButton it show this error: "java.lang.RuntimeException: Cannot create an instance of class com.tda.android_training_vangthao.viewholder.StudentViewModel" (I use Student instead of User). Please help me
@codemachine19
2 жыл бұрын
do u can solve this problem ?
2 жыл бұрын
@@codemachine19 It's been a long time so I don't remember if the problem has been solved yet
6:30 Why addUser method suspend fun? And why is there no suspend in the readAllData function? Can you explain? Thank you
@user-tl4gu8yh9j
6 ай бұрын
yes on the adduser we are inserting data and on the readalldata we are geeting data 1: it is good practice to use suspend (coroutine) to run the task asynchronously so he is using btw you can use suspend on both method 2: on the readalldata fun we are getting list through the livedata so maybe he ignored but in place of livedata if we are using flow there is no need of suspend cz flow inbuild use suspend but livedata doesnt it is lifecycle aware only
@muhammed4d
6 ай бұрын
@@user-tl4gu8yh9j So is what is being done here correct? My native language is not English, so I couldn't understand it. Is there an article?
How do you do it so fastly? And how do you remember the code, snippets, and everything? I can't even remember small codes and you are typing like a God.
@hoddiewarrior4505
3 жыл бұрын
I don't know i wonder the same thing but this is the only thing that comes to mind maybe practice
Kindly make a video to CRUD the room database using Firebase!!!
Hello Stevdza-San, this is excelent example of Room with Kotlin. But, how can we implement SearchView and query our database? Regards
@StevdzaSan
3 жыл бұрын
I will make a new video about it next week, since lots of you have asked me the same. 👍
how to check if user is added successfully.?
Please make videos on Dependency injection, Daggar, Daggar 2, Hilt...
I think your synchronized singleton implementation is wrong. When two threads enter at the same time they both pass null check, and they both will try to build instance. Synchronized block should start before null check, actually it may cover the entire function. Only one thread should be able to discover that there is no instance yet, create it and then leave synchronized block. After this other thread(s) will be allowed to enter, and get instance created by first thread.
thanks
Can someone help me out and tell me how to write the code at 12:03 in Java? Thanks!
do i need to know navigation component to study this series with you?
@StevdzaSan
4 жыл бұрын
No you don't but you should check my playlist about navigation component to learn more about it.