data: introduce Model entity and DAO; update DI module
This commit is contained in:
parent
f5e2edda87
commit
bc93c384a7
|
|
@ -10,9 +10,15 @@ import javax.inject.Singleton
|
||||||
* Main database for the application.
|
* Main database for the application.
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
@Database(entities = [SystemPromptEntity::class], version = 1, exportSchema = false)
|
@Database(
|
||||||
|
entities = [ModelEntity::class, SystemPromptEntity::class],
|
||||||
|
version = 1,
|
||||||
|
exportSchema = false
|
||||||
|
)
|
||||||
abstract class AppDatabase : RoomDatabase() {
|
abstract class AppDatabase : RoomDatabase() {
|
||||||
|
|
||||||
|
abstract fun modelDao(): ModelDao
|
||||||
|
|
||||||
abstract fun systemPromptDao(): SystemPromptDao
|
abstract fun systemPromptDao(): SystemPromptDao
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.example.llama.revamp.data.local
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Delete
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface ModelDao {
|
||||||
|
@Query("SELECT * FROM models ORDER BY dateAdded DESC")
|
||||||
|
fun getAllModels(): Flow<List<ModelEntity>> // Changed to Flow
|
||||||
|
|
||||||
|
@Query("SELECT * FROM models WHERE id = :id")
|
||||||
|
suspend fun getModelById(id: String): ModelEntity?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM models WHERE id IN (:ids)")
|
||||||
|
suspend fun getModelsByIds(ids: Collection<String>): List<ModelEntity>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insertModel(model: ModelEntity)
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
suspend fun deleteModel(model: ModelEntity)
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
suspend fun deleteModels(models: List<ModelEntity>)
|
||||||
|
|
||||||
|
@Query("UPDATE models SET lastUsed = :timestamp WHERE id = :id")
|
||||||
|
suspend fun updateLastUsed(id: String, timestamp: Long)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.example.llama.revamp.data.local
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
import com.example.llama.revamp.data.model.ModelInfo
|
||||||
|
|
||||||
|
@Entity(tableName = "models")
|
||||||
|
data class ModelEntity(
|
||||||
|
@PrimaryKey
|
||||||
|
val id: String,
|
||||||
|
val name: String,
|
||||||
|
val path: String,
|
||||||
|
val sizeInBytes: Long,
|
||||||
|
val parameters: String,
|
||||||
|
val quantization: String,
|
||||||
|
val type: String,
|
||||||
|
val contextLength: Int,
|
||||||
|
val lastUsed: Long?,
|
||||||
|
val dateAdded: Long
|
||||||
|
) {
|
||||||
|
fun toModelInfo() = ModelInfo(
|
||||||
|
id = id,
|
||||||
|
name = name,
|
||||||
|
path = path,
|
||||||
|
sizeInBytes = sizeInBytes,
|
||||||
|
parameters = parameters,
|
||||||
|
quantization = quantization,
|
||||||
|
type = type,
|
||||||
|
contextLength = contextLength,
|
||||||
|
lastUsed = lastUsed
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -38,6 +38,9 @@ abstract class AppModule {
|
||||||
@Provides
|
@Provides
|
||||||
fun provideAppDatabase(@ApplicationContext context: Context) = AppDatabase.getDatabase(context)
|
fun provideAppDatabase(@ApplicationContext context: Context) = AppDatabase.getDatabase(context)
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun providesModelDao(appDatabase: AppDatabase) = appDatabase.modelDao()
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun providesSystemPromptDao(appDatabase: AppDatabase) = appDatabase.systemPromptDao()
|
fun providesSystemPromptDao(appDatabase: AppDatabase) = appDatabase.systemPromptDao()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue