The class annotated with @Entity annotation is treated as a database component where each field represents a column in database unless annotated with @Ignore and the name of the fields maps to the name of column in database unless the field is annotated with @ColumnInfo(name = "name_you_want") .

You should have a constructor with all the fields initialized or you can have getter and setter for all the fields as i have done here for room to work.

You might have noticed the type converter, what it does is to allow storage of types which are not identifiable by sqlite by converting them to type understood by sqlite it can be achieved by writing this converter class.

And finally the database

The final piece of the puzzle is the database class that extends RoomDatabase and is annotated with @Database(“it takes all the entities and database version”).

It is an abstract class or it can be an interface usually it is the place where you will have a method to create a singleton instance of database but since i am using dagger i decided to not create it here.

It has public method to access the dao so that you can perform operations on database, it is the entry point for the database.

I have created an helper class called DbUtil which has a instance of NoteDatabase and methods that performs the database operations asynchronously.

The ViewModel

ViewModel is created by extending either the ViewModel or AndroidViewModel(provide application) class here you expose the method that the activity/fragment can perform on the database via the viewmodel the views never talk to data directly but rather through the viewmodel.