mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add cross ref table for saved item and saved item labels
This commit is contained in:
parent
23cb7cb2a5
commit
8b20a0b0be
3 changed files with 36 additions and 3 deletions
|
|
@ -3,6 +3,8 @@ package app.omnivore.omnivore.persistence
|
|||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import app.omnivore.omnivore.persistence.entities.SavedItem
|
||||
import app.omnivore.omnivore.persistence.entities.SavedItemLabel
|
||||
import app.omnivore.omnivore.persistence.entities.SavedItemAndSavedItemLabelCrossRef
|
||||
import app.omnivore.omnivore.persistence.entities.SavedItemDao
|
||||
import app.omnivore.omnivore.persistence.entities.Viewer
|
||||
import app.omnivore.omnivore.persistence.entities.ViewerDao
|
||||
|
|
@ -10,7 +12,9 @@ import app.omnivore.omnivore.persistence.entities.ViewerDao
|
|||
@Database(
|
||||
entities = [
|
||||
Viewer::class,
|
||||
SavedItem::class
|
||||
SavedItem::class,
|
||||
SavedItemLabel::class,
|
||||
SavedItemAndSavedItemLabelCrossRef::class
|
||||
],
|
||||
version = 2
|
||||
)
|
||||
|
|
|
|||
|
|
@ -97,4 +97,8 @@ interface SavedItemDao {
|
|||
|
||||
@Query("DELETE FROM savedItem WHERE savedItemId = :itemID")
|
||||
fun deleteById(itemID: String)
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT savedItemId, slug, publisherURLString, title, author, imageURLString, isArchived, pageURLString, contentReader FROM SavedItem ORDER BY savedAt DESC")
|
||||
fun getLibraryLiveDataWithLabels(): LiveData<List<SavedItemCardDataWithLabels>>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package app.omnivore.omnivore.persistence.entities
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.*
|
||||
|
||||
@Entity
|
||||
data class SavedItemLabel(
|
||||
|
|
@ -13,5 +12,31 @@ data class SavedItemLabel(
|
|||
val serverSyncStatus: Int = 0
|
||||
)
|
||||
|
||||
@Entity(primaryKeys = ["savedItemLabelId", "savedItemId"])
|
||||
data class SavedItemAndSavedItemLabelCrossRef(
|
||||
val savedItemLabelId: String,
|
||||
val savedItemId: String
|
||||
)
|
||||
|
||||
data class SavedItemWithLabels(
|
||||
@Embedded val savedItem: SavedItem,
|
||||
@Relation(
|
||||
parentColumn = "savedItemId",
|
||||
entityColumn = "savedItemLabelId",
|
||||
associateBy = Junction(SavedItemAndSavedItemLabelCrossRef::class)
|
||||
)
|
||||
val labels: List<SavedItemLabel>
|
||||
)
|
||||
|
||||
data class SavedItemCardDataWithLabels(
|
||||
@Embedded val cardData: SavedItemCardData,
|
||||
@Relation(
|
||||
parentColumn = "savedItemId",
|
||||
entityColumn = "savedItemLabelId",
|
||||
associateBy = Junction(SavedItemAndSavedItemLabelCrossRef::class)
|
||||
)
|
||||
val labels: List<SavedItemLabel>
|
||||
)
|
||||
|
||||
// has many highlights
|
||||
// has many savedItems
|
||||
|
|
|
|||
Loading…
Reference in a new issue