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 { | |
@Query("SELECT * FROM users WHERE age BETWEEN :minAge AND :maxAge") | |
fun loadAllUsersBetweenAges(minAge: Int, maxAge: Int): Array<User> | |
@Query("SELECT * FROM users WHERE first_name LIKE :search " + | |
"OR last_name LIKE :search") | |
fun findUserWithName(search: String): 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 { | |
@Query("SELECT * FROM users") | |
fun loadAllUsers(): Array<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 { | |
@Delete | |
fun deleteUsers(vararg users: 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) | |
} |
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
@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
@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
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
@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
@Transaction | |
@Query("SELECT * FROM User") | |
fun getUsersWithPlaylists(): List<UserWithPlaylists> |