【发布时间】:2020-09-11 11:03:40
【问题描述】:
我创建了这个表,但我不知道如何将数据添加到 playListWithSongs 表中。
@Entity
data class SongEntity(
var songId : Long? = null,
var name: String? = null,
)
@Entity
data class playlistEntity(
var playListId : Long? = null,
var playlistName: String? = null
)
@Entity
data class playListWithSongs(
var playlistId: Long,
var songId: Long
)
这里如何将 ids 插入到 playListWithSongs 表中?
但就我而言,播放列表可能包含相同的歌曲或为空。甚至歌曲都会出现在一个播放列表中,没有播放列表或多个播放列表,所以我如何插入 PlayListWithSongs 实体。由于两个 id 都是主键,我的播放列表将有零首歌曲,因此将有 null 并且包含重复(这里的歌曲列表和当然大小不相似)
@Insert
fun insert(playListSong: playListWithSongs)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertPlayList(playList: PlayListEntity?)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertCourse(song: SongsEntity?)
@Transaction
@Query("SELECT * FROM playListEntity")
fun getAll(): LiveData<List<PlayListWithSong>>
【问题讨论】:
标签: java android mysql kotlin android-room