Skip to content

Instantly share code, notes, and snippets.

@anangkur
Last active September 30, 2022 10:16
Show Gist options
  • Save anangkur/f3b8dc847cf60cfcd63e4311b21994b0 to your computer and use it in GitHub Desktop.
Save anangkur/f3b8dc847cf60cfcd63e4311b21994b0 to your computer and use it in GitHub Desktop.
@Entity
data class Entity(
@PrimaryKey
val id: Int,
val attributes: String,
)
@Entity
data class Entity2(
@PrimaryKey
val id: Int,
val entity1Id: Int,
val attributes: String,
)
data class EntityMerged(
@Embedded
val entity: Entity,
@Relation(
parentColumn = "id",
entityColumn = "entity1Id",
)
val entity2: List<Entity2>,
)
@Dao
interface RoomDao {
@Insert
suspend fun insertData(entity: Entity)
@Query("select * from entity join entity2 on entity.id = entity2.entity1Id join entity3 on entity.id = entity3.entity1Id")
suspend fun getAllData(): List<EntityMerged>
@Query("select * from entity join entity2 on entity.id = entity2.entity1Id join entity3 on entity.id = entity3.entity1Id")
suspend fun getAllData2(): Map<Entity, EntityMerged>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment