Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ val koverExcludedClasses = listOf(
"net.opatry.tasks.app.ui.tooling.*",
"net.opatry.tasks.data.*Dao",
"net.opatry.tasks.data.*Dao\$DefaultImpls",
"net.opatry.tasks.data.Converters",
"net.opatry.tasks.data.CoreConverters",
"net.opatry.tasks.data.entity.*",
"net.opatry.tasks.data.model.*",
"net.opatry.tasks.data.TasksAppDatabase*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Olivier Patry
* Copyright (c) 2025 Olivier Patry
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -27,28 +27,13 @@ import androidx.room.ConstructedBy
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.RoomDatabaseConstructor
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import kotlinx.datetime.Instant
import net.opatry.tasks.data.entity.TaskEntity
import net.opatry.tasks.data.entity.TaskListEntity
import net.opatry.tasks.data.entity.UserEntity


object Converters {
@TypeConverter
fun instantFromString(value: String?): Instant? = value?.let(Instant::parse)

@TypeConverter
fun instantToString(instant: Instant?): String? = instant?.toString()

@TypeConverter
fun sortingFromString(value: String?): TaskListEntity.Sorting? = value?.let(TaskListEntity.Sorting::valueOf)

@TypeConverter
fun sortingToString(sorting: TaskListEntity.Sorting?): String? = sorting?.name
}

@ConstructedBy(TasksAppDatabaseConstructor::class)
@TypeConverters(CoreConverters::class)
@Database(
entities = [
TaskListEntity::class,
Expand All @@ -61,8 +46,6 @@ object Converters {
AutoMigration(from = 2, to = 3), // add sorting column in task_list table
],
)
@ConstructedBy(TasksAppDatabaseConstructor::class)
@TypeConverters(Converters::class)
abstract class TasksAppDatabase : RoomDatabase() {
abstract fun getTaskListDao(): TaskListDao
abstract fun getTaskDao(): TaskDao
Expand Down
15 changes: 14 additions & 1 deletion tasks-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
plugins {
alias(libs.plugins.jetbrains.kotlin.multiplatform)
alias(libs.plugins.jetbrains.kotlin.serialization)
alias(libs.plugins.ksp)
}

kotlin {
Expand All @@ -41,10 +42,22 @@ kotlin {
implementation(projects.google.tasks)

implementation(libs.androidx.room.common)
implementation(libs.androidx.room.runtime)
}

commonTest.dependencies {
implementation(kotlin("test"))
}

jvmTest.dependencies {
implementation(libs.kotlinx.coroutines.test)
implementation(libs.androidx.room.testing)
implementation(libs.androidx.room.runtime)
implementation(libs.androidx.sqlite.bundled)
}
}
}
}

dependencies {
add("kspJvm", libs.androidx.room.compiler)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2025 Olivier Patry
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package net.opatry.tasks.data

import androidx.room.TypeConverter
import kotlinx.datetime.Instant
import net.opatry.tasks.data.entity.TaskListEntity


object CoreConverters {
@TypeConverter
fun instantFromString(value: String?): Instant? = value?.let(Instant::parse)

@TypeConverter
fun instantToString(instant: Instant?): String? = instant?.toString()

@TypeConverter
fun sortingFromString(value: String?): TaskListEntity.Sorting? = value?.let(TaskListEntity.Sorting::valueOf)

@TypeConverter
fun sortingToString(sorting: TaskListEntity.Sorting?): String? = sorting?.name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2025 Olivier Patry
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package net.opatry.tasks.data

import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import net.opatry.tasks.data.entity.TaskEntity
import net.opatry.tasks.data.entity.TaskListEntity

@TypeConverters(CoreConverters::class)
@Database(
entities = [
TaskEntity::class,
TaskListEntity::class,
],
version = 1,
exportSchema = false,
)
abstract class TasksCoreTestDatabase : RoomDatabase() {
abstract fun getTaskListDao(): TaskListDao
abstract fun getTaskDao(): TaskDao
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

package net.opatry.tasks.data

import androidx.room.Room
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import net.opatry.tasks.data.entity.TaskEntity
import net.opatry.tasks.data.util.inMemoryTasksAppDatabaseBuilder
import org.junit.After
import kotlin.test.BeforeTest
import kotlin.test.Test
Expand All @@ -42,16 +42,15 @@ class TaskDaoTest {
private val now: Instant
get() = Clock.System.now()

private lateinit var db: TasksAppDatabase
private lateinit var db: TasksCoreTestDatabase
private lateinit var taskDao: TaskDao

@BeforeTest
fun createDb() {
db = inMemoryTasksAppDatabaseBuilder()
db = Room.inMemoryDatabaseBuilder<TasksCoreTestDatabase>()
.setDriver(BundledSQLiteDriver())
.build()
taskDao = db.getTaskDao()
taskDao = db.getTaskDao()
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

package net.opatry.tasks.data

import androidx.room.Room
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import net.opatry.tasks.data.entity.TaskEntity
import net.opatry.tasks.data.entity.TaskListEntity
import net.opatry.tasks.data.util.inMemoryTasksAppDatabaseBuilder
import org.junit.After
import kotlin.test.BeforeTest
import kotlin.test.Test
Expand All @@ -42,13 +42,13 @@ class TaskListDaoTest {
private val now: Instant
get() = Clock.System.now()

private lateinit var db: TasksAppDatabase
private lateinit var db: TasksCoreTestDatabase
private lateinit var taskListDao: TaskListDao
private lateinit var taskDao: TaskDao

@BeforeTest
fun createDb() {
db = inMemoryTasksAppDatabaseBuilder()
db = Room.inMemoryDatabaseBuilder<TasksCoreTestDatabase>()
.setDriver(BundledSQLiteDriver())
.build()
taskListDao = db.getTaskListDao()
Expand Down
Loading