用途:为 Android 项目提供 Room 持久化层的模式参考,覆盖从依赖配置到测试的完整链路。
主要能力:实体定义(@Entity、索引、@ColumnInfo、@Ignore)、嵌入对象(@Embedded 前缀)、关系查询(@Relation 组合 UserWithPosts)、DAO 接口(Flow 响应式查询、suspend 一次性操作、@Insert/@Update/@Delete、OnConflictStrategy、@Transaction)、TypeConverters(Date、枚举、字符串列表 JSON 序列化)、@Database 类与版本管理、Migration 迁移与开发期破坏性回退、Koin 依赖注入、Repository 与 ViewModel 的 Flow/StateFlow 集成、内存数据库单元测试。
必要用法:在 build.gradle.kts 中启用 KSP 插件并添加 Room 依赖,roomVersion 为 2.6.1,使用 room-runtime、room-ktx、room-compiler(ksp)与 room-testing。数据库通过 Room.databaseBuilder 构建并 addMigrations;测试使用 Room.inMemoryDatabaseBuilder 与 allowMainThreadQueries。
适用场景:Android 应用本地数据存储、响应式 UI 数据流、数据库版本升级与迁移测试。
限制:资料未提供具体性能数据、兼容性范围或收费信息;fallbackToDestructiveMigration 仅建议用于 debug 构建。