syncended
syncended

Reputation: 91

Room database get Set of type

I need to get set of strings from RoomDatabase

Entity:

@Entity
data class Data(
@PrimaryKey val id: Int,
val type: String,
val photo: String
)

I need to get set of types. I've try follow method:

...
@Query("SELECT type FROM data")
fun getAllTypes(): LiveData<Set<String>>
...

Now I has next error:

C:\...\storage\DataDao.java:24: error: Not sure how to convert a Cursor to this method's return type (androidx.lifecycle.LiveData<java.util.Set<java.lang.String>>).
    public abstract androidx.lifecycle.LiveData<java.util.Set<java.lang.String>> getAllTypes();
[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).

> Task :app:kaptDebugKotlin FAILED

Upvotes: 1

Views: 858

Answers (2)

mlc
mlc

Reputation: 415

You can't get Set, sorry. According to documentation for SELECT queries you can use only List or Array.

https://developer.android.com/reference/androidx/room/Query

If you need to have unique items you can use SQL's DISTINCT.

Upvotes: 3

Hasan Bou Taam
Hasan Bou Taam

Reputation: 4035

Maybe this:

@Query("SELECT type FROM data")

Must be this:

@Query("SELECT type FROM Data")

Upvotes: -1

Related Questions