mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: Move database related stuff to data module
This commit is contained in:
parent
66354205f1
commit
fc171c1e0a
44 changed files with 36 additions and 49 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -6,4 +6,5 @@
|
|||
.idea/
|
||||
*iml
|
||||
*.iml
|
||||
*/build
|
||||
*/build
|
||||
*/*/build
|
||||
|
|
|
@ -10,7 +10,6 @@ plugins {
|
|||
kotlin("plugin.serialization")
|
||||
id("kotlin-parcelize")
|
||||
id("com.google.android.gms.oss-licenses-plugin")
|
||||
id("app.cash.sqldelight")
|
||||
id("com.google.gms.google-services") apply false
|
||||
id("com.google.firebase.crashlytics") apply false
|
||||
}
|
||||
|
@ -141,16 +140,6 @@ android {
|
|||
}
|
||||
|
||||
namespace = "eu.kanade.tachiyomi"
|
||||
|
||||
sqldelight {
|
||||
databases {
|
||||
create("Database") {
|
||||
packageName.set("tachiyomi.data")
|
||||
dialect(libs.sqldelight.dialects.sql)
|
||||
schemaOutputDirectory.set(project.file("./src/main/sqldelight"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -223,7 +212,6 @@ dependencies {
|
|||
implementation(libs.play.services.gcm)
|
||||
|
||||
// Database
|
||||
implementation(libs.bundles.db)
|
||||
implementation(libs.sqlite.android)
|
||||
implementation(libs.bundles.sqlite)
|
||||
//noinspection UseTomlInstead
|
||||
|
|
|
@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.data.database
|
|||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
|
||||
import co.touchlab.kermit.Logger
|
||||
import tachiyomi.data.Database
|
||||
import yokai.data.Database
|
||||
|
||||
class DbOpenCallback : AndroidSqliteDriver.Callback(Database.Schema) {
|
||||
|
||||
|
|
|
@ -27,13 +27,13 @@ import kotlinx.serialization.json.Json
|
|||
import nl.adaptivity.xmlutil.XmlDeclMode
|
||||
import nl.adaptivity.xmlutil.core.XmlVersion
|
||||
import nl.adaptivity.xmlutil.serialization.XML
|
||||
import tachiyomi.data.Database
|
||||
import uy.kohesive.injekt.api.InjektModule
|
||||
import uy.kohesive.injekt.api.InjektRegistrar
|
||||
import uy.kohesive.injekt.api.addSingleton
|
||||
import uy.kohesive.injekt.api.addSingletonFactory
|
||||
import uy.kohesive.injekt.api.get
|
||||
import yokai.data.AndroidDatabaseHandler
|
||||
import yokai.data.Database
|
||||
import yokai.data.DatabaseHandler
|
||||
import yokai.domain.SplashState
|
||||
import yokai.domain.storage.StorageManager
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package yokai.data
|
||||
|
||||
import app.cash.sqldelight.ColumnAdapter
|
||||
import java.util.*
|
||||
|
||||
val dateAdapter = object : ColumnAdapter<Date, Long> {
|
||||
override fun decode(databaseValue: Long): Date = Date(databaseValue)
|
||||
override fun encode(value: Date): Long = value.time
|
||||
}
|
||||
|
||||
private const val listOfStringsSeparator = ", "
|
||||
val listOfStringsAdapter = object : ColumnAdapter<List<String>, String> {
|
||||
override fun decode(databaseValue: String) =
|
||||
if (databaseValue.isEmpty()) {
|
||||
listOf()
|
||||
} else {
|
||||
databaseValue.split(listOfStringsSeparator)
|
||||
}
|
||||
override fun encode(value: List<String>) = value.joinToString(separator = listOfStringsSeparator)
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
plugins {
|
||||
kotlin("multiplatform")
|
||||
kotlin("plugin.serialization")
|
||||
id("app.cash.sqldelight")
|
||||
id("com.android.library")
|
||||
}
|
||||
|
||||
|
@ -9,10 +10,12 @@ kotlin {
|
|||
sourceSets {
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
api(libs.bundles.db)
|
||||
}
|
||||
}
|
||||
val androidMain by getting {
|
||||
dependencies {
|
||||
api(libs.bundles.db.android)
|
||||
implementation(projects.sourceApi)
|
||||
}
|
||||
}
|
||||
|
@ -22,3 +25,13 @@ kotlin {
|
|||
android {
|
||||
namespace = "yokai.data"
|
||||
}
|
||||
|
||||
sqldelight {
|
||||
databases {
|
||||
create("Database") {
|
||||
packageName.set("yokai.data")
|
||||
dialect(libs.sqldelight.dialects.sql)
|
||||
schemaOutputDirectory.set(project.file("./src/commonMain/sqldelight"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import kotlinx.coroutines.CoroutineDispatcher
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.withContext
|
||||
import tachiyomi.data.Database
|
||||
|
||||
class AndroidDatabaseHandler(
|
||||
val db: Database,
|
|
@ -1,6 +1,8 @@
|
|||
package eu.kanade.tachiyomi.data.database
|
||||
|
||||
import app.cash.sqldelight.ColumnAdapter
|
||||
import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
||||
import java.util.*
|
||||
|
||||
// TODO: Move to yokai.data.DatabaseAdapter
|
||||
|
||||
|
@ -13,14 +15,18 @@ val updateStrategyAdapter = object : ColumnAdapter<UpdateStrategy, Int> {
|
|||
override fun encode(value: UpdateStrategy): Int = value.ordinal
|
||||
}
|
||||
|
||||
interface ColumnAdapter<T : Any, S> {
|
||||
/**
|
||||
* @return [databaseValue] decoded as type [T].
|
||||
*/
|
||||
fun decode(databaseValue: S): T
|
||||
|
||||
/**
|
||||
* @return [value] encoded as database type [S].
|
||||
*/
|
||||
fun encode(value: T): S
|
||||
val dateAdapter = object : ColumnAdapter<Date, Long> {
|
||||
override fun decode(databaseValue: Long): Date = Date(databaseValue)
|
||||
override fun encode(value: Date): Long = value.time
|
||||
}
|
||||
|
||||
private const val listOfStringsSeparator = ", "
|
||||
val listOfStringsAdapter = object : ColumnAdapter<List<String>, String> {
|
||||
override fun decode(databaseValue: String) =
|
||||
if (databaseValue.isEmpty()) {
|
||||
listOf()
|
||||
} else {
|
||||
databaseValue.split(listOfStringsSeparator)
|
||||
}
|
||||
override fun encode(value: List<String>) = value.joinToString(separator = listOfStringsSeparator)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package yokai.data
|
|||
|
||||
import app.cash.sqldelight.Query
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import tachiyomi.data.Database
|
||||
|
||||
interface DatabaseHandler {
|
||||
suspend fun <T> await(inTransaction: Boolean = false, block: suspend Database.() -> T): T
|
|
@ -83,7 +83,7 @@ sqlite-framework = { module = "androidx.sqlite:sqlite-framework", version.ref =
|
|||
sqlite-ktx = { module = "androidx.sqlite:sqlite-ktx", version.ref = "sqlite" }
|
||||
sqlite-android = { module = "com.github.requery:sqlite-android", version = "3.45.0" }
|
||||
|
||||
sqldelight-coroutines = { module = "app.cash.sqldelight:coroutines-extensions-jvm", version.ref = "sqldelight" }
|
||||
sqldelight-coroutines = { module = "app.cash.sqldelight:coroutines-extensions", version.ref = "sqldelight" }
|
||||
sqldelight-android-driver = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }
|
||||
sqldelight-android-paging = { module = "app.cash.sqldelight:androidx-paging3-extensions", version.ref = "sqldelight" }
|
||||
sqldelight-dialects-sql = { module = "app.cash.sqldelight:sqlite-3-38-dialect", version.ref = "sqldelight" }
|
||||
|
@ -104,7 +104,8 @@ gradle-versions = { id = "com.github.ben-manes.versions", version = "0.42.0" }
|
|||
|
||||
[bundles]
|
||||
archive = [ "common-compress", "junrar" ]
|
||||
db = [ "sqldelight-android-driver", "sqldelight-android-paging", "sqldelight-coroutines" ]
|
||||
db = [ "sqldelight-coroutines" ]
|
||||
db-android = [ "sqldelight-android-driver", "sqldelight-android-paging" ]
|
||||
coil = [ "coil3", "coil3-svg", "coil3-gif", "coil3-okhttp" ]
|
||||
logging = [ "kermit" ]
|
||||
sqlite = [ "sqlite-framework", "sqlite-ktx" ]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue