Kodeindb 错误,无法在我的视图模型中访问我的数据对象
Kodeindb error, cant access my data object in my viewmodel
我有一个数据 class 存储在数据库中。
@kotlinx.serialization.Serializable
data class SavedCalculation(
override val id: String,
val model1: Model1,
val model2: Model2
):org.kodein.db.model.orm.Metadata {
}
@kotlinx.serialization.Serializable
data class Model1(
var attr1: String = "",
var attr2: String = "",
)
@kotlinx.serialization.Serializable
data class Model2(
var attr1: String = "",
var attr2: String = "",
)
如果我在我的视图模型中调用我的 savedCalculation 对象;
var saved = mutableStateOf<List<SavedCalculation>>(listOf())
private set
fun load(){
viewModelScope.launch {
useCases.load.invoke().collect { response ->
when(response){
is Response.Loading -> {
}
is Response.Success -> {
saved.value = response.data
saved.value[0].model1 -> **this causes error.**
}
is Response.Error -> {}
}
}
}
}
错误:
Cannot access 'org.kodein.db.model.orm.HasMetadata' which is a supertype of 'com.myapp.data.model.SavedCalculationDto'. Check your module classpath for missing or conflicting dependencies
我的主包和数据包是单独的 gradle 构建文件,因此 kodeindb 无法从我的视图模型访问依赖项。
我只是在 build.gradle.kts 中添加了相同的 kodeindb 依赖项,我的问题就解决了。
//into viewmodel package gradle file:
implementation("org.kodein.db:kodein-db-jvm:0.8.1-beta")
implementation("org.kodein.db:kodein-db-serializer-kotlinx:0.8.1-beta")
implementation("org.kodein.db:kodein-leveldb-jni-jvm-windows:0.8.1-beta")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
我有一个数据 class 存储在数据库中。
@kotlinx.serialization.Serializable
data class SavedCalculation(
override val id: String,
val model1: Model1,
val model2: Model2
):org.kodein.db.model.orm.Metadata {
}
@kotlinx.serialization.Serializable
data class Model1(
var attr1: String = "",
var attr2: String = "",
)
@kotlinx.serialization.Serializable
data class Model2(
var attr1: String = "",
var attr2: String = "",
)
如果我在我的视图模型中调用我的 savedCalculation 对象;
var saved = mutableStateOf<List<SavedCalculation>>(listOf())
private set
fun load(){
viewModelScope.launch {
useCases.load.invoke().collect { response ->
when(response){
is Response.Loading -> {
}
is Response.Success -> {
saved.value = response.data
saved.value[0].model1 -> **this causes error.**
}
is Response.Error -> {}
}
}
}
}
错误:
Cannot access 'org.kodein.db.model.orm.HasMetadata' which is a supertype of 'com.myapp.data.model.SavedCalculationDto'. Check your module classpath for missing or conflicting dependencies
我的主包和数据包是单独的 gradle 构建文件,因此 kodeindb 无法从我的视图模型访问依赖项。 我只是在 build.gradle.kts 中添加了相同的 kodeindb 依赖项,我的问题就解决了。
//into viewmodel package gradle file:
implementation("org.kodein.db:kodein-db-jvm:0.8.1-beta")
implementation("org.kodein.db:kodein-db-serializer-kotlinx:0.8.1-beta")
implementation("org.kodein.db:kodein-leveldb-jni-jvm-windows:0.8.1-beta")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")