Friday 7 December 2018

Android Architecture Components : Room DB Introduction

Hi All,

Today I am going to share my understanding about Room Database. First , let's start with why Room?
Actually when we have SQLite Open Helper class , then what is the need of Room . This can be easily understood by understanding the difference between them.

Sqlite vs Room :

  • Sqlite deals with raw queries where as in Room DB there is no raw queries.
  • In Sqlite , no compile time verification of raw sql queries , but in Room DB compiler checks the Sqlite statement
  • In Sqlite , lots of boilerplate code we had to write to conversion between Sqlite statement and java data objects, but in Room DB boilerplate code is less due to mapping between DB objects and java objects.
  • Sqlite apis are low level , so more time and more effort is required to build apps.In Room DB , it makes easy when used with Live Data and ViewModel
So , because of the above reasons , Room is a good option to work with.

What is Room
  • Database Layer on top of Sqlite.
  • Provides an abstraction layer over Sqlite to allow fluent database access
  • Object Relation Mapping(ORM) library 
Room Database Components :

Entity :
  •  Defines schema of database table
  •  annotated with @Entity
 
Dao:
  • contains method to access database
  • annotated with @Dao

Database:
  • It is database holder class 
  • annotated with @Database
Our android application uses Dao , to access the Sqlite database.These data access objects are used to perform db related operations.
Entities are used to get and set the fields of Database table to android application.This way components of Room are related to each other.
 
For more information , you can check the official android developers video

That's it , for this post , in next post I will share a demo for Room DB 





No comments:

Post a Comment

Advanced Kotlin Coroutines : Introduction

 Hi,  Today I am unwraping the topic in Kotin world i.e. Coroutine . If you want to get started with Kotlin coroutine and ease your daily de...