‫Hello, my friends, and welcome back.
‫In this video, we'll start learning about the room database in Android.
‫I want from you to focus with me because it's very important topic and many people make errors in room
‫database SQLite database is an open source database provided in Android, which is used to store data
‫inside the user's device in form of a text file.
‫We can perform so many operations on this data, such as adding new data, updating, reading and deleting
‫this data.
‫SQLite is an offline database that is locally stored in the user's device, and we don't have to create
‫any connection to connect to this database room.
‫Database room is an ORM object relational mapping library.
‫In other words, room will map our database objects to Java objects room provides an abstraction layer
‫over SQLite to allow fluent database access while harnessing the full power of SQLite.
‫So a room database is a powerful and flexible library that provides an abstraction layer over SQLite,
‫A lightweight relational database management system room simplifies database operations and makes it
‫easier for developers to work with database in their Android applications.
‫It's a part of the Android architecture components and prompts the use of the Mvvm model.
‫View ViewModel Architecture Pattern.
‫In the next videos we'll talk about this pattern SQLite versus room database.
‫In the case of SQLite, there is no compile time verification of the row SQL queries, but in room there
‫is some validation at compile time and this is very important and good point For the room database,
‫you need to use lots of boilerplate code to convert between SQL queries and Java database objects.
‫But room maps our database objects to Java objects without boilerplate code.
‫As your schema changes, you need to update the affected SQL queries manually.
‫Room solves this problem Room is built to work with live data and rxjava for data observation while
‫SQL Light doesn't.
‫Room has three main components of room database, entity, Dao and database.
‫Let's talk about these components in details.
‫The first component is the entity.
‫The entity represents a table within the database and has to be annotated with at entity annotation.
‫Each entity consists of a minimum of one field has to define a primary key.
‫The second component is the Dao database access object.
‫In room, you use data access objects to access and manage your data.
‫The Dao is the main component of room and includes methods that offer access to your app's database.
‫It has to be annotated with at Dao annotation the are used instead of query builders and let you separate
‫different components of your database.
‫For example, current data and statistics which allows you to easily test your database.
‫The third component is the database database serves as the database holder and is the main access point
‫to your relational data.
‫It has to be annotated with at database annotation and extends the room database.
‫It also contains and returns the Dao data access object.
‫If you notice that we're going to use the annotations at entity at the I O and add database to tell
‫Android studio about the role of each class.