‫The second step in creating our database is to create the Dao.
‫Dao stands for Data Access Object, and it's a critical component of the room database library in Android.
‫The IO is an interface that defines a set of methods for performing database operations on entities
‫database tables.
‫A Dao is an interface annotated with at Dao annotation.
‫So let's go to Android studio and build this Dao.
‫I'll create a new Java class select interface and I'll name it as contact Dao and I'll annotate it with
‫the a o.
‫A Dao is an interface annotated with Dao annotation.
‫It specifies a contract for interacting with the database, including methods for inserting, updating,
‫deleting or querying data.
‫I'll start by creating the first method void insert and I need to insert a contact object of type contacts.
‫So I need to pass contacts and I name it as contact.
‫This method is responsible for inserting data into a database table and I'll annotate it with insert
‫annotation and this annotation marks a method.
‫As an insert operation, I can create other annotations.
‫Update, delete and query.
‫I'll create another method called delete and I need to delete a specific contact.
‫So for that I need to specify the contact object and I'll mark it as delete with the delete annotation
‫to mark a method as a delete operation, you can define custom SQL queries within the Dao methods using
‫the Add query annotation.
‫So add query annotation and here you need to specify the SQL query.
‫This allows you to execute complex database operations while still benefiting from rooms type safety
‫and the query annotation allows you to define custom SQL queries and map the results to Java or Kotlin
‫objects.
‫So for that I need to create a method called Get all contacts.
‫And this method returning type should be a list of contact objects.
‫So list of contact objects that we have created before alt plus enter to import the class of the list
‫from Java util and here I need to specify the SQL query in this annotation I need to use select which
‫is an SQL query all from and I need to specify the name of the table.
‫If I go to the contacts here, the table name is contacts table, I'll copy it because it's a case sensitive
‫and paste it here.
‫So select all, get all contacts from the contacts table.
‫This is how we create custom queries, how to delete and and insert new contacts into our database using
‫the contact Dao By using the OS in room, you can interact with your database in a structured and efficient
‫manner while also benefiting from room's features like type, safety thread, safety and automatic query
‫generation.