Implemented data classes for database optimisations

This commit is contained in:
denizk0461
2023-04-17 12:09:54 +02:00
parent 199aa8f44c
commit 4d520f375b
5 changed files with 60 additions and 9 deletions
@@ -3,9 +3,10 @@ package com.denizk0461.studip.model
import androidx.room.Entity import androidx.room.Entity
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
@Entity(tableName = "offers") //@Entity(tableName = "offers")
data class CanteenOffer( data class CanteenOffer(
@PrimaryKey val id: Int, // @PrimaryKey val id: Int,
val id: Int,
val date: String, val date: String,
val dateId: Int, // gives every item on the same day the same ID for easier filtering val dateId: Int, // gives every item on the same day the same ID for easier filtering
// val canteen: Int, // val canteen: Int,
@@ -1,6 +1,12 @@
package com.denizk0461.studip.model package com.denizk0461.studip.model
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(
tableName = "offer_canteen",
)
data class OfferCanteen( data class OfferCanteen(
val id: Int, @PrimaryKey val id: Int,
val canteen: String, val canteen: String,
) )
@@ -1,8 +1,30 @@
package com.denizk0461.studip.model package com.denizk0461.studip.model
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey
@Entity(
tableName = "offer_category",
foreignKeys = [
ForeignKey(
OfferDate::class,
["id"],
["date_id"],
ForeignKey.CASCADE,
),
ForeignKey(
OfferCanteen::class,
["id"],
["canteen_id"],
ForeignKey.CASCADE,
),
]
)
data class OfferCategory( data class OfferCategory(
val id: Int, @PrimaryKey val id: Int,
val dateId: Int, @ColumnInfo(name = "date_id") val dateId: Int,
val canteenId: Int, @ColumnInfo(name = "canteen_id") val canteenId: Int,
val category: String, val category: String,
) )
@@ -1,6 +1,12 @@
package com.denizk0461.studip.model package com.denizk0461.studip.model
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(
tableName = "offer_date",
)
data class OfferDate( data class OfferDate(
val id: Int, @PrimaryKey val id: Int,
val date: String, val date: String,
) )
@@ -1,8 +1,24 @@
package com.denizk0461.studip.model package com.denizk0461.studip.model
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey
@Entity(
tableName = "offer_item",
foreignKeys = [
ForeignKey(
OfferCategory::class,
["id"],
["category_id"],
ForeignKey.CASCADE,
),
]
)
data class OfferItem( data class OfferItem(
val id: Int, @PrimaryKey val id: Int,
val categoryId: Int, @ColumnInfo(name = "category_id") val categoryId: Int,
val title: Int, val title: Int,
val price: String, val price: String,
val isFair: Boolean, val isFair: Boolean,