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