This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
data class User( | |
@PrimaryKey val userId: Long, | |
val name: String, | |
val age: Int | |
) | |
@Entity(foreignKeys = @ForeignKey(entity = User.class, | |
parentColumns = "userId", | |
childColumns = "userOwnerId", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transaction | |
@Query("SELECT * FROM User") | |
fun getUsersAndLibraries(): List<UserAndLibrary> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
data class User( | |
@PrimaryKey val userId: Long, | |
val name: String, | |
val age: Int | |
) | |
@Entity(foreignKeys = @ForeignKey(entity = User.class, | |
parentColumns = "userId", | |
childColumns = "userCreatorId", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transaction | |
@Query("SELECT * FROM User") | |
fun getUsersWithPlaylists(): List<UserWithPlaylists> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
data class Playlist( | |
@PrimaryKey val id: Long, | |
val playlistName: String | |
) | |
@Entity | |
data class Song( | |
@PrimaryKey val id: Long, | |
val songName: String, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class PlaylistWithSongs( | |
@Embedded val playlist: Playlist, | |
@Relation( | |
parentColumn = "playlistId", | |
entityColumn = "songId", | |
associateBy = @Junction(PlaylistSongCrossRef::class) | |
) | |
val songs: List<Song> | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transaction | |
@Query("SELECT * FROM Playlist") | |
fun getPlaylistsWithSongs(): List<PlaylistWithSongs> | |
@Transaction | |
@Query("SELECT * FROM Song") | |
fun getSongsWithPlaylists(): List<SongWithPlaylists> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Database(entities = arrayOf(User::class), version = 1) | |
@TypeConverters(Converters::class) | |
abstract class UserDatabase : RoomDatabase() { | |
abstract fun userDao(): UserDao | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Dao | |
interface UserDao { | |
@Insert(onConflict = OnConflictStrategy.REPLACE) | |
fun insertUsers(vararg users: User) | |
@Insert | |
fun insertBothUsers(user1: User, user2: User) | |
@Insert | |
fun insertUsersAndFriends(user: User, friends: List<User>) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Dao | |
interface UserDao { | |
@Update(onConflict = OnConflictStrategy.REPLACE) | |
fun updateUsers(vararg users: User) | |
@Update | |
fun update(user: User) | |
} |