Reading_Notes

View the Project on GitHub Hiba-Almade/Reading_Notes

##Room

Save data in a local database using Room

Primary components:

Defining data using Room entities:

Each entity corresponds to a table in Room database, and each instance of an entity represents a row of data in the corresponding table.

  1. Anatomy of an entity
    • Each Room entity can be defined as a class that is annotated with @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.
    • Room uses the class name as the database table name.
  2. Define a primary key
    • Each Room entity must define a primary key that uniquely identifies each row in the corresponding database table. The most straightforward way of doing this is to annotate a single column with @PrimaryKey.
  3. Ignore fields
  1. Provide table search support Room supports several types of annotations that make it easier for you to search for details in your database’s tables.

Define relationships between objects:

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.

Accessing data using Room DAOs: