Room is one of the Android App Architecture Components. The Room persistence library (Object Relational Mapping library) provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite. It will map our database objects to Java objects.
Its features include:
- Less boilerplate code
- SQL Validation at compile time – incorrect SQL statements will be picked up
- Built to work with LiveData and RxJava for data observation
Room uses Annotations and has 3 main components:
- @Entity – to define our database tables
- @DAO – provides an API for reading and writing data
- @Database – represents a database holder. Includes a list of @Entity and @DAO annotations and allow us to create a new database or acquire a connection to our db at runtime
To add the dependencies for Room, see here.
