2023-10-11 18:13:32 +02:00

30 lines
883 B
Kotlin

package com.github.libretube.db
import androidx.room.TypeConverter
import com.github.libretube.api.JsonHelper
import com.github.libretube.extensions.toLocalDateSafe
import java.nio.file.Path
import kotlin.io.path.Path
import kotlinx.datetime.LocalDate
import kotlinx.serialization.encodeToString
object Converters {
@TypeConverter
fun localDateToString(localDate: LocalDate?) = localDate?.toString()
@TypeConverter
fun stringToLocalDate(string: String?) = string?.toLocalDateSafe()
@TypeConverter
fun pathToString(path: Path?) = path?.toString()
@TypeConverter
fun stringToPath(string: String?) = string?.let { Path(it) }
@TypeConverter
fun stringListToJson(value: List<String>) = JsonHelper.json.encodeToString(value)
@TypeConverter
fun jsonToStringList(value: String) = JsonHelper.json.decodeFromString<List<String>>(value)
}