Skip to content

Commit 3f61715

Browse files
committed
Isolate Room converters in tasks-core to allow reuse
1 parent 3340855 commit 3f61715

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ val koverExcludedClasses = listOf(
8585
"net.opatry.tasks.app.ui.tooling.*",
8686
"net.opatry.tasks.data.*Dao",
8787
"net.opatry.tasks.data.*Dao\$DefaultImpls",
88-
"net.opatry.tasks.data.Converters",
88+
"net.opatry.tasks.data.CoreConverters",
8989
"net.opatry.tasks.data.entity.*",
9090
"net.opatry.tasks.data.model.*",
9191
"net.opatry.tasks.data.TasksAppDatabase*",

tasks-app-shared/src/commonMain/kotlin/net/opatry/tasks/data/TasksAppDatabase.kt

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Olivier Patry
2+
* Copyright (c) 2025 Olivier Patry
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining
55
* a copy of this software and associated documentation files (the "Software"),
@@ -27,28 +27,11 @@ import androidx.room.ConstructedBy
2727
import androidx.room.Database
2828
import androidx.room.RoomDatabase
2929
import androidx.room.RoomDatabaseConstructor
30-
import androidx.room.TypeConverter
3130
import androidx.room.TypeConverters
32-
import kotlinx.datetime.Instant
3331
import net.opatry.tasks.data.entity.TaskEntity
3432
import net.opatry.tasks.data.entity.TaskListEntity
3533
import net.opatry.tasks.data.entity.UserEntity
3634

37-
38-
object Converters {
39-
@TypeConverter
40-
fun instantFromString(value: String?): Instant? = value?.let(Instant::parse)
41-
42-
@TypeConverter
43-
fun instantToString(instant: Instant?): String? = instant?.toString()
44-
45-
@TypeConverter
46-
fun sortingFromString(value: String?): TaskListEntity.Sorting? = value?.let(TaskListEntity.Sorting::valueOf)
47-
48-
@TypeConverter
49-
fun sortingToString(sorting: TaskListEntity.Sorting?): String? = sorting?.name
50-
}
51-
5235
@Database(
5336
entities = [
5437
TaskListEntity::class,
@@ -62,7 +45,7 @@ object Converters {
6245
],
6346
)
6447
@ConstructedBy(TasksAppDatabaseConstructor::class)
65-
@TypeConverters(Converters::class)
48+
@TypeConverters(CoreConverters::class)
6649
abstract class TasksAppDatabase : RoomDatabase() {
6750
abstract fun getTaskListDao(): TaskListDao
6851
abstract fun getTaskDao(): TaskDao
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2025 Olivier Patry
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the Software
9+
* is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20+
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
package net.opatry.tasks.data
24+
25+
import androidx.room.TypeConverter
26+
import kotlinx.datetime.Instant
27+
import net.opatry.tasks.data.entity.TaskListEntity
28+
29+
30+
object CoreConverters {
31+
@TypeConverter
32+
fun instantFromString(value: String?): Instant? = value?.let(Instant::parse)
33+
34+
@TypeConverter
35+
fun instantToString(instant: Instant?): String? = instant?.toString()
36+
37+
@TypeConverter
38+
fun sortingFromString(value: String?): TaskListEntity.Sorting? = value?.let(TaskListEntity.Sorting::valueOf)
39+
40+
@TypeConverter
41+
fun sortingToString(sorting: TaskListEntity.Sorting?): String? = sorting?.name
42+
}

0 commit comments

Comments
 (0)