v79
10/18/2022, 7:30 PMv79
10/22/2022, 11:14 AMgetCurrentOdometer
is a suspend function (because, I think, all repository functions which call the DB are supposed to be suspend?) Note that I don't want a LiveData result - it's not going to change value suddenly!Tower Guidev2
10/27/2022, 9:00 AM@Insert(onConflict = OnConflictStrategy.REPLACE)
actually replaces an existing row?
or do i have to do something "clever" myself?v79
10/29/2022, 8:38 AMLocalDateTime
). I'm trying to write a query which would return all events in the last X number of days:
fun getEventsWithin(days: Int): Flow<List<Event>>
I'm really struggling to work out what the SQL would be. The Event
entity has a column called dateTime
of type LocalDateTime
and I have written two @TypeConverter
functions which convert between LocalDateTime
and Long
values.IsaacMart
11/04/2022, 3:51 PMBwaim
11/15/2022, 6:06 PMMap<CategoryEntity, List<CategoryEntity>>
. So, making a query joining on the same table :
@Query(
"SELECT * FROM category as parent" +
"JOIN category as child ON parent.id = child.parent_id"
)
fun loadCategoriesAndSubCategories(): Map<CategoryEntity, List<CategoryEntity>>
It's not working because it's mapping with the column name. I tried to rename all the columns, but it doesn't work too.
Someone knows if it's possible to do it ?v79
11/19/2022, 9:39 AMLiveData
and the other is not? Because I think I need that.Ademir Queiroga
01/13/2023, 9:37 AM[ksp] [MissingType]: Element 'com.admqueiroga.data.models.Foo' references a type that is not present - com.admqueiroga.data.models.Foo
ms
02/14/2023, 1:25 PMBackupAgent
or BackupAgentHelper
?Bradleycorn
02/28/2023, 4:06 PM@Query(
"SELECT * FROM user" +
"JOIN book ON user.id = book.user_id"
)
fun loadUserAndBookNames(): Map<User, List<Book>>
Can I use a typealias with this? Like so:
typealias BookWorms: Map<User, List<Book>>
@Query(
"SELECT * FROM user" +
"JOIN book ON user.id = book.user_id"
)
fun loadUserAndBookNames(): BookWorms
Michael Vandendriessche
03/14/2023, 10:08 AMRoom.inMemoryDatabaseBuilder
supposed to be destroyed and recreated again for every test? Like in this example in the documentation https://developer.android.com/training/data-storage/room/testing-db
Is it optimized for constant recreation or is the performance hit very small? It looks to me like the db instance could be reused and we just clear everything. Maybe the performance gain is negligible.
Thanks!Chris Fillmore
03/15/2023, 11:08 PMBradleycorn
04/13/2023, 8:42 PM@Entity(...)
data class MyEntity(
val id: Int,
val name: String,
@Ignore
val otherField: String = ""
)
Is there some way that I can make Room “ignore” otherfield
in terms of table creation and writing to the table, but use it when reading from a query and creating an instance of MyEntity
?
I’d like to make a query method like this:
@Query("SELECT me.*, sot.otherField FROM " +
"MyEntity me " +
"JOIN SomeOtherTable.sot on me.id = sot.id " +
"WHERE me.id = :id")
fun getEntity(id: Int): Flow<MyEntity>
This doesn’t work (otherField is always an empty string), I guess cause I told Room to @Ignore
it.
would be cool if I could to something like @Ignore(write=true, read=false)
or something like that.Mario Adam
04/27/2023, 12:06 PMandroidx.room:room-ktx:2.5.1
and androidx.room:room-compiler:2.5.1
along with ksp
I have declared a dao with
@Dao
interface IDepotDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insert(depot: Depot)
@Query("DELETE FROM depots")
suspend fun deleteAll()
@Transaction
suspend fun rebuild(entities: List<Depot>) {
deleteAll()
entities.forEach {
insert(it)
}
}
}
When building the module, a build error is thrown stating that some IDepotDao.DefaultImpls
symbol was not found. Building works, when I remove that method.
Someone has an idea on what I might be doing wrong?Bradleycorn
07/11/2023, 7:08 PMfallbackToDestructiveMigration()
to facilitate new versions. No problem.
In the newest version, we have removed a table/entity. Compounding things, that table/entity had a foreign key. When the new version is installed, Room does NOT remove the old table (I understand why). So, we need to define an AutoMigration and use @DeleteTable
to remove the old table that is no longer needed. Our new database is version 5 (previous version that had the table was 4). So I’ve defined an Automigration with (from = 4, to = 5, spec = MyMigrationSpec::class)
.
Sure enough if I have the app installed with db version 4 and then install a new build that has db version 5, the migration runs and the table is deleted.
But, if I have an older build of the app installed with say db version 2, and then I install a new build with db version 5, the migration does NOT run and the table is NOT deleted. I added an onPostMigrate
implementation with some debug code to confirm that it doesn’t run.
What gives? even though I’m going from 2 -> 5, I thought it would find the version 4 schema, and do a (destructive) migration from 2 -> 4 and then apply the the AutoMigration from 4-> 5 … But that doesn’t seem to be the case. Surely I don’t have to create my own migrations for every possible combination of from/to versions that users could be updating across, right?Huan
07/24/2023, 7:32 PMJetbrains Ttvna
07/31/2023, 5:11 PMChuck Stein
08/21/2023, 5:18 PMjava.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
Here is my query:
@Query("SELECT isCompleted FROM $ONBOARDING_STATUS_TABLE_NAME WHERE type = :featureEducationType")
suspend fun isCompleted(featureEducationType: FeatureEducationType): Boolean
I'm not sure how the query is returning null, because the column is defined with a default value:
@Entity(tableName = "table_onboarding_status")
data class OnboardingStatus(
@ColumnInfo(name = "type") @PrimaryKey val type: FeatureEducationType,
@ColumnInfo(name = "isCompleted", defaultValue = "0") val isCompleted: Boolean,
)
Abhi
08/29/2023, 2:09 PMval room_version = "2.5.2"
implementation("androidx.room:room-ktx:$room_version")
kapt("androidx.room:room-compiler:$room_version")
and this is how my dao file looks like.
interface CurrencyDao {
@Insert
fun insertCurrency(currency: Currency): Long
@Query("SELECT * FROM Currency")
suspend fun fetchCurrencies(): List<Currency>
}
and i'm getting below error on build. i saw top slackoverflow results for above. but it was not helpful.
error: Not sure how to convert a Cursor to this method's return type (java.lang.Object).
public abstract java.lang.Object fetchCurrencies(@org.jetbrains.annotations.NotNull
Rudy Sulley
11/16/2023, 9:16 AMPre-packaged database has an invalid schema:
I have the full question over on stackoverflow at https://stackoverflow.com/questions/77493447/using-compressed-prepopulated-database-with-roomAbhimanyu
11/18/2023, 7:30 AMOnConflictStrategy.ABORT
or OnConflictStrategy.IGNORE
specifically for @Update
?
My understanding is for @Insert
, if there is an existing data matching the given primary key, it creates a conflict and we can resolve using
ABORT - to abort the transaction. The transaction is rolled back.
IGNORE - An Insert DAO method that returns the inserted rows ids will return -1 for rows that are not inserted since this strategy will ignore the row if there is a conflict.
REPLACE - An Insert DAO method that returns the inserted rows ids will never return -1 since this strategy will always insert a row even if there is a conflict.
But, since @Update
is used to modify existing data, what is the use-case for OnConflictStrategy.ABORT
or OnConflictStrategy.IGNORE
?
OnConflictStrategy.REPLACE
will allow us to update the data as I expect.mattchowning
12/01/2023, 7:55 PMnull
value existing in our app's database in a column with a not null
constraint. I'm having trouble figuring out what could be causing that to happen.
Because the spike occurred suddenly without any code changes to the app, my suspicion is that some kind of corrupted input must have caused it (the table is filled by parsing json that our server provides). I'm not seeing any obvious problems in the input we were providing, but I'm also not sure if there's something specific I should be looking for. Does anyone have any ideas? There are more details about the issue in the GitHub issue description if you're curious. Thanks for your help!MV
12/02/2023, 11:18 PM@Query("UPDATE account set current = 0 where current = 1")
suspend fun removeCurrent()
@Query("UPDATE account set current = 1 where id = :accountId")
suspend fun setCurrent(accountId: Int)
@Query("SELECT * FROM account where current = 1 limit 1")
fun getCurrent(): LiveData<Account?>
I have some function observing the current account (getCurrent).
The problem is when I swap between account I do, removeCurrent(), setCurrent(acc)
.
But between the calls of those two queries my livedata updates and subsequentially updates the consumers.
I would like to avoid that
(What I get from getCurrent: oldAcc, null, newAcc; What I want oldAcc, newAcc)Trey
01/12/2024, 2:55 PMJohn Jaiver Rodriguez
01/20/2024, 12:43 AMBradford Canonigo
02/04/2024, 10:51 AM[MissingType]: Element 'com.example.notes.framework.db.NoteEntity' references a type that is not present
e: [ksp] androidx.room.RoomKspProcessor was unable to process 'com.example.notes.framework.db.DatabaseService' because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
e: Error occurred in KSP, check log for detail
Luis
02/08/2024, 2:09 AM0xf1f1
02/11/2024, 8:34 AM0xf1f1
02/27/2024, 4:41 AMPeter Enyedi
02/29/2024, 3:10 PM