##Room
Setup - add these depencies: dependencies { def room_version = “2.2.6”
Each entity corresponds to a table in Room database, and each instance of an entity represents a row of data in the corresponding table.
@Entity
. A Room entity includes fields for each column in the corresponding table in the database, including one or more columns that comprise the primary key.@PrimaryKey
.@Ignore
, and can use ignoredColumns for an entity inherits fields from a parent entity.SQLite is a relational database, so you can specify relationships between entities.
Create embedded objects
@Embedded
annotation - represents an object that you’d like to decompose into its subfields within a table.
One-to-one relationship - between two entities is a relationship where each instance of the parent entity corresponds to exactly one instance of the child entity.
One-to-many relationship between two entities is a relationship where each instance of the parent entity corresponds to zero or more instances of the child entity, but each instance of the child entity can only correspond to exactly one instance of the parent entity.
Many-to-many relationship between two entities is a relationship where each instance of the parent entity corresponds to zero or more instances of the child entity, and vice-versa.
Nested relationships - if you might need to query a set of three or more tables that are all related to each other.
Annotate your DAOs with @Dao
@Insert
annotation - allows you to define methods that insert their parameters into a table in the database.@Update
annotation - allows you to define methods that update specific rows in a database table.@Delete
annotation - allows you to define methods that delete specific rows from a database table.@Query
annotation - allows you to write SQL statements and expose them as DAO methods.