SQlite Database VS Room persistence library
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:
- @Entity — Define our database tables
- @DAO — Provide an API for reading and writing data
- @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
Farhad Ba-ali
Updated on November 13, 2020Comments
-
Farhad Ba-ali over 3 years
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.
-
JeneralJames over 5 yearsGood, clear answer which sums up the key benefits of using Room. Only comment I would make is that the link provided is just a rehash of the official documentation (but with less detail and clarity). I'd recommend referring to the google developer docs instead developer.android.com/training/data-storage/room
-
Sankalp over 5 years@JeneralJames thanks for your valuable suggestion, I have included the link to the google developer docs in this answer.
-
DragonFire about 4 yearsI am facing slow load problem with Room in viewpager fragment... please see here : stackoverflow.com/q/57392635/3904109