SQlite Database VS Room persistence library

Farhad Ba-ali picture Farhad Ba-ali · Jun 1, 2018 · Viewed 24.1k times · Source

I need help for my exam project to find differences and benefit of ROOM database: I tried to search in android development documentation to understand the difference between these two databases, but i couldn't clearly understand. I did not find any answer in stack overflow either. I also want to know the benefit of using Room persistence compared to SQLite database.

Hope someone can give me clear answer.

Answer

Sankalp picture Sankalp · Jun 25, 2018

Room is an ORM, Object Relational Mapping library. In other words, Room will map our database objects to Java objects. Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite.

Difference between SQLite and Room persistence library:-

  • In case of SQLite, There is no compile time verification of raw SQLite queries. But in Room there is SQL validation at compile time.
  • As your schema changes, you need to update the affected SQL queries manually. Room solves this problem.
  • You need to use lots of boilerplate code to convert between SQL queries and Java data objects. But, Room maps our database objects to Java Object without boilerplate code.
  • Room is built to work with LiveData and RxJava for data observation, while SQLite does not.

Room annotations and main components:

  1. @Entity — Define our database tables
  2. @DAO — Provide an API for reading and writing data
  3. @Database — Represent a database holder

Here is the link to the medium article which explains in detail the usage and benefits of Room persistence library. I hope this helps.

Edit 1: You can refer to Google developer docs, which clearly explains how to save data in a local database using room. Link to Google Developer Docs