Skip to content

Room ‐ Annotations

Devrath edited this page Oct 23, 2023 · 1 revision
Annotations Usage
@Entity It is used to denote that the data class is a table that has defined columns in the table where we can add rows as entered
@PrimaryKey It is used to indicate that the values are unique for each row and is primarily used to differentiate between the rows.
@ColumnInfo It is used to give a custom name for the column of a table. It is useful where the room can identify them while writing queries.
@Dao It is used to indicate the interface is a data access object where we specify the operations to be performed on the tables in the database.
@TypeConverters It is used to mention the class that is responsible for converting the complex data type to the primitive type and vice versa since the room is aware of just primitive types.
@Database It is used to make the abstract class a database class. This class extends RoomDatabase.
@Embeded and @Relation This is used to flatten the tables and provide a link between them so that we don't need to write a making function using the DAO's for example in the repository layer.
@ForiegnKey This is used to build a relationship between the tables so that invalid operations can be prevented and handled in a certain way.