Skip to content

Commit

Permalink
Resolve SqlDelight database column error
Browse files Browse the repository at this point in the history
  • Loading branch information
KaushalVasava committed Aug 8, 2023
1 parent e0f360a commit 4fc3754
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -101,7 +102,13 @@ fun TaskList(viewModel: TaskViewModel) {
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Top
) {
items(tasks) {
items(tasks.filter { !it.isDone }) {
TaskItem(viewModel, it)
}
item {
Text("Completed")
}
items(tasks.filter { it.isDone }) {
TaskItem(viewModel, it)
}
}
Expand Down Expand Up @@ -134,7 +141,7 @@ fun TaskList(viewModel: TaskViewModel) {
@Composable
fun TaskItem(viewModel: TaskViewModel, task: Task2) {
var isCompleted by remember {
mutableStateOf(false)
mutableStateOf(task.isDone)
}
Card(
Modifier.padding(4.dp).clip(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ class TaskViewModel(driver: SqlDriver) : ViewModel() {
fun update(title: String, isDone: Boolean, id: Long) {
viewModelScope.launch(Dispatchers.IO) {
database.updateTask(title, isDone, id)
// val d = database.getTasksList()
getTasks()
print("Data ${tasks.value.toList()}")
// tasks.value = d
}
}
}
4 changes: 2 additions & 2 deletions shared/src/commonMain/kotlin/database/Task.sq
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ WHERE id = ?;

updateTask:
UPDATE Task
SET title = ?, isDone = ?
WHERE id = ?;
SET title = :title, isDone = :isDone
WHERE id = :id;

0 comments on commit 4fc3754

Please sign in to comment.