Create a Room entity with DAO.
Generates a Room entity with DAO, updates AppDatabase, and adds Hilt provider. Use when adding new local database tables to your Android app.
/plugin marketplace add ggz23/android-interview-plugin/plugin install ggz23-android-interview@ggz23/android-interview-pluginCreate a Room entity with DAO.
$ARGUMENTS - Entity description (e.g., "Product with id, name, price")
Explore Project Structure
data/local/entity/)Create entity:
@Entity(tableName = "{names}")
data class {Name}Entity(
@PrimaryKey val id: String,
val name: String,
// other fields
)
@Dao
interface {Name}Dao {
@Query("SELECT * FROM {names}")
fun getAll(): Flow<List<{Name}Entity>>
@Query("SELECT * FROM {names} WHERE id = :id")
suspend fun getById(id: String): {Name}Entity?
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(item: {Name}Entity)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(items: List<{Name}Entity>)
@Delete
suspend fun delete(item: {Name}Entity)
}
Update AppDatabase:
@Database(entities = [...])abstract fun {name}Dao(): {Name}DaoAdd provider to database Hilt module:
@Provides
fun provide{Name}Dao(database: AppDatabase): {Name}Dao =
database.{name}Dao()