Skip to content

Commit

Permalink
Bump sqldelight to 2.0.0 (#771)
Browse files Browse the repository at this point in the history
* Update libs.versions.toml

* Use web-worker driver

---------

Co-authored-by: hfhbd <[email protected]>
  • Loading branch information
hfhbd and hfhbd authored Aug 11, 2023
1 parent db34cc2 commit def4ba9
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.softwork.composetodo

import android.content.*
import app.cash.sqldelight.async.coroutines.*
import app.cash.sqldelight.driver.android.*
import app.softwork.composetodo.repository.*
import app.softwork.composetodo.repository.TodoRepository.Companion.createDatabase
Expand All @@ -15,7 +16,9 @@ import io.ktor.serialization.kotlinx.json.*
import kotlinx.coroutines.flow.*

class Container(applicationContext: Context) : AppContainer {
private val db = createDatabase(AndroidSqliteDriver(ComposeTodoDB.Schema, applicationContext, "composetodo.db"))
private val db = createDatabase(
AndroidSqliteDriver(ComposeTodoDB.Schema.synchronous(), applicationContext, "composetodo.db")
)

override val client = HttpClient(Android) {
defaultRequest {
Expand Down
8 changes: 1 addition & 7 deletions clients/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sqldelight {
databases.register("ComposeTodoDB") {
packageName.set("app.softwork.composetodo")
deriveSchemaFromMigrations.set(true)
verifyMigrations.set(true)
generateAsync.set(true)
}
}

Expand Down Expand Up @@ -94,12 +94,6 @@ kotlin {
val iosSimulatorArm64Test by getting {
dependsOn(iosTest)
}

val jsMain by getting {
dependencies {
api(libs.sqldelight.sqljsDriver)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.softwork.composetodo.repository

import app.cash.sqldelight.async.coroutines.*
import app.cash.sqldelight.coroutines.*
import app.cash.sqldelight.db.*
import app.softwork.composetodo.*
Expand Down Expand Up @@ -35,7 +36,7 @@ interface TodoRepository {
}

override suspend fun deleteAll() {
val allIDs = dao.allIDs().executeAsList()
val allIDs = dao.allIDs().awaitAsList()
dao.deleteAll()
allIDs.forEach { id ->
api.deleteTodo(id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.softwork.composetodo

import app.cash.sqldelight.async.coroutines.*
import app.cash.sqldelight.driver.native.*
import app.softwork.composetodo.repository.*
import app.softwork.composetodo.viewmodels.*
Expand All @@ -18,7 +19,9 @@ class IosContainer(
protocol: URLProtocol,
host: String
) : AppContainer {
private val db = TodoRepository.createDatabase(NativeSqliteDriver(ComposeTodoDB.Schema, "composetodo.db"))
private val db = TodoRepository.createDatabase(
NativeSqliteDriver(ComposeTodoDB.Schema.synchronous(), "composetodo.db")
)

constructor() : this(protocol = URLProtocol.HTTPS, host = "api.todo.softwork.app")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.softwork.composetodo

import app.cash.sqldelight.async.coroutines.*
import app.cash.sqldelight.db.*
import app.cash.sqldelight.driver.jdbc.sqlite.*
import app.softwork.composetodo.repository.*
Expand All @@ -18,7 +19,7 @@ class DesktopContainer : AppContainer {
private val db: ComposeTodoDB
init {
val driver: SqlDriver = JdbcSqliteDriver("jdbc:sqlite:composetodo.db")
ComposeTodoDB.Schema.migrate(driver, 0, 1)
ComposeTodoDB.Schema.synchronous().migrate(driver, 0, 1)
db = createDatabase(driver)
}
override fun todoViewModel(api: API.LoggedIn): TodoViewModel =
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ coroutines = "1.7.3"
datetime = "0.4.0"
serialization = "1.5.1"
ktor = "2.3.3"
sqldelight = "2.0.0-alpha05"
sqldelight = "2.0.0"
cloudkit = "0.1.0"

[libraries]
Expand All @@ -19,7 +19,7 @@ serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-jso
sqldelight-sqliteDriver = { module = "app.cash.sqldelight:sqlite-driver", version.ref = "sqldelight" }
sqldelight-androidDriver = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }
sqldelight-nativeDriver = { module = "app.cash.sqldelight:native-driver", version.ref = "sqldelight" }
sqldelight-sqljsDriver = { module = "app.cash.sqldelight:sqljs-driver", version.ref = "sqldelight" }
sqldelight-sqljsDriver = { module = "app.cash.sqldelight:web-worker-driver", version.ref = "sqldelight" }
sqldelight-coroutinesExtensions = { module = "app.cash.sqldelight:coroutines-extensions", version.ref = "sqldelight" }

apacheCompress = { module = "org.apache.commons:commons-compress", version = "1.23.0" }
Expand Down
13 changes: 9 additions & 4 deletions kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# yarn lockfile v1


"@cashapp/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@cashapp/sqldelight-sqljs-worker/-/sqldelight-sqljs-worker-2.0.0.tgz#16c0138a9611905272019481b2c6abfcb55f9ba8"
integrity sha512-mdavcZ0KnY9LvUfs6Z3o9bDXumpVxICvgBSSo570anDhOGwak3ttU0YbkAtDsyqLIhBLGwGEUqyyDLJ1LqPndg==

"@colors/[email protected]":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
Expand Down Expand Up @@ -2607,10 +2612,10 @@ spdy@^4.0.2:
select-hose "^2.0.0"
spdy-transport "^3.0.0"

sql.js@1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/sql.js/-/sql.js-1.7.0.tgz#cadfed9773b643fbba0fc1ed1847e3a647e1fcb9"
integrity sha512-qAfft3xkSgHqmmfNugWTp/59PsqIw8gbeao5TZmpmzQQsAJ49de3iDDKuxVixidYs6dkHNksY8m27v2dZNn2jw==
sql.js@1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/sql.js/-/sql.js-1.8.0.tgz#cb45d957e17a2239662fe2f614c9b678990867a6"
integrity sha512-3HD8pSkZL+5YvYUI8nlvNILs61ALqq34xgmF+BHpqxe68yZIJ1H+sIVIODvni25+CcxHUxDyrTJUL0lE/m7afw==

[email protected]:
version "2.0.1"
Expand Down
5 changes: 4 additions & 1 deletion web/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ dependencies {
implementation(libs.bootstrapCompose)
implementation(libs.routingCompose)

implementation(npm("sql.js", "1.7.0"))
implementation(libs.sqldelight.sqljsDriver)
implementation(npm("@cashapp/sqldelight-sqljs-worker", "2.0.0"))
implementation(npm("@cashapp/sqldelight-sqljs-worker", "2.0.0"))
implementation(npm("sql.js", "1.8.0"))
implementation(devNpm("copy-webpack-plugin", "9.1.0"))

testImplementation(kotlin("test"))
Expand Down
8 changes: 6 additions & 2 deletions web/src/main/kotlin/app/softwork/composetodo/Main.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package app.softwork.composetodo

import app.cash.sqldelight.driver.sqljs.*
import app.cash.sqldelight.driver.worker.*
import kotlinx.coroutines.*
import org.jetbrains.compose.web.*
import org.w3c.dom.*

suspend fun main() {
// https://youtrack.jetbrains.com/issue/KTOR-539
Expand All @@ -14,7 +15,10 @@ window.fetch = function (resource, init) {
};
"""
)
val driver = initSqlDriver(ComposeTodoDB.Schema).await()
val driver = WebWorkerDriver(
Worker(js("""new URL("@cashapp/sqldelight-sqljs-worker/sqljs.worker.js", import.meta.url)"""))
)
ComposeTodoDB.Schema.migrate(driver, 0, 1).await()
renderComposable(rootElementId = "root") {
val appContainer = WebContainer(driver)
MainApp(appContainer)
Expand Down

0 comments on commit def4ba9

Please sign in to comment.