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 getAllLiveData(): LiveData<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
Room.databaseBuilder( | |
applicationContext, | |
UserDatabase::class.java, | |
"users-db" | |
).fallbackToDestructiveMigration() | |
.build() |
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
Room.databaseBuilder( | |
applicationContext, | |
UserDatabase::class.java, | |
"users-db" | |
).addMigrations(MIGRATION_1_2) | |
.build() |
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
val MIGRATION_1_2 = object : Migration(1, 2) { | |
override fun migrate(database: SupportSQLiteDatabase) { | |
database.execSQL("ALTER TABLE users ADD COLUMN age INTEGER") | |
} | |
} |
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
public final class UserDao_Impl implements UserDao { | |
private final RoomDatabase __db; | |
private final EntityInsertionAdapter<User> __insertionAdapterOfUser; | |
private final EntityDeletionOrUpdateAdapter<User> __deletionAdapterOfUser; | |
public UserDao_Impl(RoomDatabase __db) { | |
this.__db = __db; | |
this.__insertionAdapterOfUser = new EntityInsertionAdapter<User>(__db) { |
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
public final class UserDatabase_Impl extends UserDatabase { | |
private volatile UserDao _userDao; | |
@Override | |
protected SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration configuration) { | |
//Implementation | |
} | |
@Override | |
protected InvalidationTracker createInvalidationTracker() { |
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_TABLE") | |
fun getAll(): List<User> | |
@Insert | |
fun insertAll(vararg users: User) | |
@Delete | |
fun delete(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 BookDao { | |
@Query( | |
"SELECT * FROM book " + | |
"INNER JOIN loan ON loan.book_id = book.id " + | |
"INNER JOIN user ON user.id = loan.user_id " + | |
"WHERE users.name LIKE :userName" | |
) | |
fun findBooksBorrowedByNameSync(userName: String): List<Book> | |
} |
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(): Cursor | |
} |
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 NameTuple( | |
@ColumnInfo(name = "first_name") val firstName: String?, | |
@ColumnInfo(name = "last_name") val lastName: String? | |
) | |
@Dao | |
interface UserDao { | |
@Query("SELECT first_name, last_name FROM users") | |
fun loadFullName(): List<NameTuple> | |
} |