Room database for local persistence

1419
0

Room provides an abstraction layer over SQLite for compile-time verified database access. I define entities with @Entity annotation, specifying table structure and relationships. DAOs (Data Access Objects) marked with @Dao contain query methods using @Query, @Insert, @Update, and @Delete. Room generates implementation at compile time. The @Database annotation creates the database instance. Migrations handle schema changes safely. Room works seamlessly with coroutines and Flow for reactive queries. Type converters handle complex types like Date or List. Foreign keys enforce relationships. Prepopulating databases uses createFromAsset(). Room's compile-time verification catches SQL errors before runtime.