Delete
@Target(allowedTargets = [AnnotationTarget.FUNCTION])
@Retention(value = AnnotationRetention.BINARY)
public annotation Delete
Marks a function in a Dao annotated class as a delete function.
The implementation of the function will delete its parameters from the database.
All the parameters of the delete function must either be classes annotated with Entity or collections / array of it.
Example:
@Dao
interface MusicDao {
@Delete
suspend fun deleteSongs(vararg songs: Song)
@Delete
suspend fun deleteAlbumAndSongs(album: Album, songs: List<Song>)
}
If a target entity is specified via entity value then the parameters can be of arbitrary data object types that will be interpreted as partial entities. For example:
@Entity
data class Playlist (
@PrimaryKey
val playlistId: Long,
val ownerId: Long,
val name: String,
@ColumnInfo(defaultValue = "normal")
val category: String
)
data class OwnerIdAndCategory (
val ownerId: Long,
val category: String
)
@Dao
interface PlaylistDao {
@Delete(entity = Playlist::class)
suspend fun deleteByOwnerIdAndCategory(varargs idCategory: OwnerIdAndCategory)
}
Summary
Public constructors
Public methods
getEntity
public final @NonNull KClass<@NonNull ?> getEntity()
The target entity of the delete function.
When this is declared, the delete function parameters are interpreted as partial entities when the type of the parameter differs from the target. The data object class that represents the entity must contain a subset of the properties of the target entity. The properties value will be used to find matching entities to delete.
By default, the target entity is interpreted by the function parameters.