room: add indices

pull/653/merge
Varun Patil 2023-08-21 12:36:39 -07:00
parent 6dfe308268
commit 3fb209a994
2 changed files with 22 additions and 12 deletions

View File

@ -9,7 +9,7 @@ import gallery.memories.R
import gallery.memories.mapper.Photo import gallery.memories.mapper.Photo
@Database(entities = [Photo::class], version = 8) @Database(entities = [Photo::class], version = 9)
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
abstract fun photoDao(): PhotoDao abstract fun photoDao(): PhotoDao

View File

@ -2,18 +2,28 @@ package gallery.memories.mapper
import androidx.room.ColumnInfo import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
@Entity(tableName="photos") @Entity(
data class Photo ( tableName = "photos", indices = [
@PrimaryKey(autoGenerate = true) val id: Int? = null, Index(value = ["local_id"]),
@ColumnInfo(name="local_id") val localId: Long, Index(value = ["auid"]),
@ColumnInfo(name="auid") val auid: Long, Index(value = ["dayid"]),
@ColumnInfo(name="mtime") val mtime: Long, Index(value = ["flag"]),
@ColumnInfo(name="date_taken") val dateTaken: Long, Index(value = ["bucket_id"]),
@ColumnInfo(name="dayid") val dayId: Long, Index(value = ["bucket_id", "dayid"])
@ColumnInfo(name="basename") val baseName: String, ]
@ColumnInfo(name="bucket_id") val bucketId: Long, )
@ColumnInfo(name="bucket_name") val bucketName: String, data class Photo(
@ColumnInfo(name="flag") val flag: Int @PrimaryKey(autoGenerate = true) val id: Int? = null,
@ColumnInfo(name = "local_id") val localId: Long,
@ColumnInfo(name = "auid") val auid: Long,
@ColumnInfo(name = "mtime") val mtime: Long,
@ColumnInfo(name = "date_taken") val dateTaken: Long,
@ColumnInfo(name = "dayid") val dayId: Long,
@ColumnInfo(name = "basename") val baseName: String,
@ColumnInfo(name = "bucket_id") val bucketId: Long,
@ColumnInfo(name = "bucket_name") val bucketName: String,
@ColumnInfo(name = "flag") val flag: Int
) )