Skip to content

Commit abbe606

Browse files
committed
revert: "refactor: Replace Requery's SQLite with AndroidX's new KMP SQLite"
This reverts commit f604e4e.
1 parent 7ac42d5 commit abbe606

File tree

5 files changed

+60
-38
lines changed

5 files changed

+60
-38
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ The format is simplified version of [Keep a Changelog](https://keepachangelog.co
4949
- Refactor Library to store LibraryMap instead of flatten list of LibraryItem
5050
- LibraryItem abstraction to make it easier to manage
5151
- LibraryManga no longer extend MangaImpl
52-
- Replace Requery's SQLite with AndroidX's new KMP SQLite
5352
- Update dependency gradle to v8.12
5453
- Update user agent (@Hiirbaf)
5554
- Update serialization to v1.8.1
@@ -66,7 +65,8 @@ The format is simplified version of [Keep a Changelog](https://keepachangelog.co
6665
- Update dependency com.getkeepsafe.taptargetview:taptargetview to v1.15.0
6766
- Update dependency androidx.window:window to v1.4.0
6867
- Update dependency androidx.webkit:webkit to v1.13.0
69-
- Update androidxSqlite to v2.5.1
68+
- Update dependency androidx.sqlite:sqlite-ktx to v2.5.1
69+
- Update dependency androidx.sqlite:sqlite to v2.5.1
7070
- Update dependency androidx.recyclerview:recyclerview to v1.4.0
7171
- Update dependency androidx.core:core-ktx to v1.16.0
7272
- Update dependency androidx.compose:compose-bom to v2025.05.01

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ dependencies {
200200
implementation(libs.play.services.gcm)
201201

202202
// Database
203+
implementation(libs.sqlite.android)
203204
implementation(libs.bundles.sqlite)
204205

205206
// Model View Presenter

app/src/main/java/yokai/core/di/AppModule.kt

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,12 @@ package yokai.core.di
22

33
import android.app.Application
44
import androidx.core.content.ContextCompat
5-
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
6-
import androidx.sqlite.driver.bundled.SQLITE_OPEN_CREATE
7-
import androidx.sqlite.driver.bundled.SQLITE_OPEN_READWRITE
5+
import androidx.sqlite.db.SupportSQLiteDatabase
86
import app.cash.sqldelight.db.SqlDriver
7+
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
98
import co.touchlab.kermit.Logger
109
import com.chuckerteam.chucker.api.ChuckerCollector
1110
import com.chuckerteam.chucker.api.ChuckerInterceptor
12-
import com.eygraber.sqldelight.androidx.driver.AndroidxSqliteConfiguration
13-
import com.eygraber.sqldelight.androidx.driver.AndroidxSqliteDatabaseType
14-
import com.eygraber.sqldelight.androidx.driver.AndroidxSqliteDriver
15-
import com.eygraber.sqldelight.androidx.driver.File
16-
import com.eygraber.sqldelight.androidx.driver.SqliteJournalMode
17-
import com.eygraber.sqldelight.androidx.driver.SqliteSync
1811
import eu.kanade.tachiyomi.BuildConfig
1912
import eu.kanade.tachiyomi.core.storage.AndroidStorageFolderProvider
2013
import eu.kanade.tachiyomi.data.cache.ChapterCache
@@ -30,6 +23,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper
3023
import eu.kanade.tachiyomi.source.SourceManager
3124
import eu.kanade.tachiyomi.util.chapter.ChapterFilter
3225
import eu.kanade.tachiyomi.util.manga.MangaShortcutManager
26+
import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory
3327
import kotlinx.serialization.json.Json
3428
import kotlinx.serialization.protobuf.ProtoBuf
3529
import nl.adaptivity.xmlutil.XmlDeclMode
@@ -48,23 +42,46 @@ fun appModule(app: Application) = module {
4842
single { app }
4943

5044
single<SqlDriver> {
51-
AndroidxSqliteDriver(
52-
createConnection = { name ->
53-
BundledSQLiteDriver().open(name, SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE)
54-
},
55-
databaseType = AndroidxSqliteDatabaseType.File(app, "tachiyomi.db"),
56-
configuration = AndroidxSqliteConfiguration().apply {
57-
isForeignKeyConstraintsEnabled = true
58-
journalMode = SqliteJournalMode.WAL
59-
sync = SqliteSync.Normal
60-
},
45+
AndroidSqliteDriver(
6146
schema = Database.Schema,
62-
onCreate = {
63-
Logger.d { "Creating new database..." }
64-
},
65-
onUpdate = { oldVersion, newVersion ->
66-
if (oldVersion < newVersion) {
67-
Logger.d { "Upgrading database from $oldVersion to $newVersion" }
47+
context = app,
48+
name = "tachiyomi.db",
49+
// factory = if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
50+
// // Support database inspector in Android Studio
51+
// FrameworkSQLiteOpenHelperFactory()
52+
// } else {
53+
// RequerySQLiteOpenHelperFactory()
54+
// },
55+
factory = RequerySQLiteOpenHelperFactory(),
56+
callback = object : AndroidSqliteDriver.Callback(Database.Schema) {
57+
override fun onOpen(db: SupportSQLiteDatabase) {
58+
super.onOpen(db)
59+
setPragma(db, "foreign_keys = ON")
60+
setPragma(db, "journal_mode = WAL")
61+
setPragma(db, "synchronous = NORMAL")
62+
}
63+
64+
private fun setPragma(db: SupportSQLiteDatabase, pragma: String) {
65+
val cursor = db.query("PRAGMA $pragma")
66+
cursor.moveToFirst()
67+
cursor.close()
68+
}
69+
70+
// Not sure if this is still needed, but just in case
71+
override fun onConfigure(db: SupportSQLiteDatabase) {
72+
db.setForeignKeyConstraintsEnabled(true)
73+
}
74+
75+
override fun onCreate(db: SupportSQLiteDatabase) {
76+
Logger.d { "Creating new database..." }
77+
super.onCreate(db)
78+
}
79+
80+
override fun onUpgrade(db: SupportSQLiteDatabase, oldVersion: Int, newVersion: Int) {
81+
if (oldVersion < newVersion) {
82+
Logger.d { "Upgrading database from $oldVersion to $newVersion" }
83+
super.onUpgrade(db, oldVersion, newVersion)
84+
}
6885
}
6986
},
7087
)

gradle/androidx.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ multidex = { module = "androidx.multidex:multidex", version = "2.0.1" }
2828
palette = { module = "androidx.palette:palette", version = "1.0.0" }
2929
preference = { module = "androidx.preference:preference-ktx", version = "1.2.1" }
3030
recyclerview = { module = "androidx.recyclerview:recyclerview", version = "1.4.0" }
31+
sqlite = { module = "androidx.sqlite:sqlite", version = "2.5.1" }
3132
webkit = { module = "androidx.webkit:webkit", version = "1.13.0" }
3233
work = { module = "androidx.work:work-runtime-ktx", version = "2.10.1" }
3334
window = { module = "androidx.window:window", version = "1.4.0" }
@@ -37,7 +38,7 @@ androidx = [
3738
"activity", "activity-compose", "annotation", "appcompat", "browser", "biometric", "cardview", "core",
3839
"core-splashscreen", "layout-constraint", "glance-appwidget", "lifecycle-common", "lifecycle-livedata",
3940
"lifecycle-process", "lifecycle-runtime", "lifecycle-viewmodel", "lifecycle-viewmodel-compose", "multidex",
40-
"palette", "preference", "recyclerview", "layout-swiperefresh", "webkit", "work", "window"
41+
"palette", "preference", "recyclerview", "sqlite", "layout-swiperefresh", "webkit", "work", "window"
4142
]
4243

4344
[plugins]

gradle/libs.versions.toml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ fast_adapter = "5.7.0"
66
moko = "0.24.5"
77
okhttp = "5.0.0-alpha.16"
88
shizuku = "13.1.5"
9-
androidxSqlite = "2.5.1"
10-
# FIXME: Stay at 2.0.2 until 2.1.1 released because dialect is borked
11-
# REF: https://github.com/sqldelight/sqldelight/issues/5758
9+
# FIXME: Uncomment once SQLDelight support KMP AndroidX SQLiteDriver
10+
#sqlite = "2.5.0-alpha04"
11+
sqlite = "2.5.1"
1212
sqldelight = "2.0.2"
1313
junit = "5.11.3"
1414
kermit = "2.0.5"
@@ -82,12 +82,13 @@ rxjava = { module = "io.reactivex:rxjava", version = "1.3.8" }
8282
rxandroid = { module = "io.reactivex:rxandroid", version = "1.2.1" }
8383
slice = { module = "com.github.mthli:Slice", version = "v1.2" }
8484

85-
# SQLite interface
86-
sqlite = { module = "androidx.sqlite:sqlite", version.ref = "androidxSqlite" }
87-
sqlite-bundled = { module = "androidx.sqlite:sqlite-bundled", version.ref = "androidxSqlite" }
85+
# FIXME: Uncomment once SQLDelight support KMP AndroidX SQLiteDriver
86+
#sqlite = { module = "androidx.sqlite:sqlite-bundled", version.ref = "sqlite" }
87+
sqlite-ktx = { module = "androidx.sqlite:sqlite-ktx", version.ref = "sqlite" }
88+
sqlite-android = { module = "com.github.requery:sqlite-android", version = "3.49.0" }
8889

8990
sqldelight-coroutines = { module = "app.cash.sqldelight:coroutines-extensions", version.ref = "sqldelight" }
90-
sqldelight-androidx-driver = { module = "com.eygraber:sqldelight-androidx-driver", version = "0.0.12" }
91+
sqldelight-android-driver = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }
9192
sqldelight-android-paging = { module = "app.cash.sqldelight:androidx-paging3-extensions", version.ref = "sqldelight" }
9293
sqldelight-dialects-sql = { module = "app.cash.sqldelight:sqlite-3-38-dialect", version.ref = "sqldelight" }
9394

@@ -113,11 +114,13 @@ moko = { id = "dev.icerock.mobile.multiplatform-resources", version.ref = "moko"
113114
sqldelight = { id = "app.cash.sqldelight", version.ref = "sqldelight" }
114115

115116
[bundles]
116-
db = [ "sqldelight-coroutines", "sqldelight-androidx-driver" ]
117-
db-android = [ "sqldelight-android-paging" ]
117+
db = [ "sqldelight-coroutines" ]
118+
db-android = [ "sqldelight-android-driver", "sqldelight-android-paging" ]
118119
coil = [ "coil3", "coil3-svg", "coil3-gif", "coil3-okhttp" ]
119120
logging = [ "kermit" ]
120-
sqlite = [ "sqlite", "sqlite-bundled" ]
121+
# FIXME: Uncomment once SQLDelight support KMP AndroidX SQLiteDriver
122+
#sqlite = [ "sqlite", "sqlite-ktx" ]
123+
sqlite = [ "sqlite-ktx" ]
121124
test = [ "junit-api", "kotest-assertions", "mockk" ]
122125
test-android = [ "junit-android" ]
123126
test-runtime = [ "junit-engine" ]

0 commit comments

Comments
 (0)