miércoles, 8 de septiembre de 2021

Android: LiveData and Room: Setup

Setup

Project's gradle 
Module's gradle


Room

Room has three main components of Room DB :

  • Entity
  • Dao
  • Database
  1. Entity - Represents a table within the database. Room creates a table for each class that has @Entity annotation

    1. @PrimaryKey(autoGenerate = true)
    2. @ColumnInfo(name = “column_name”)
    3. @Ignore — field will not be persisted by Room
    4. @Embeded — nested fields can be referenced directly in the SQL queries.

  2. Dao - DAOs are responsible for defining the methods that access the database.

  3. Database - Contains the database holder and serves as the main access point for the underlying connection to your app’s persisted, relational data.

Example

(See on preview for gists visibility)
  1. SleepNight entity

  2. Dao

  3. Database

No hay comentarios:

Publicar un comentario