Skip to content

Commit 69840be

Browse files
committed
driver modified to use sqldelight 2.0.0
1 parent 3e62883 commit 69840be

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

build.gradle.kts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import io.gitlab.arturbosch.detekt.Detekt
2+
import kotlinx.kover.gradle.plugin.dsl.KoverReportExtension
23
import org.jetbrains.kotlin.gradle.targets.js.yarn.yarn
34
import java.util.*
5+
import javax.xml.catalog.CatalogFeatures.defaults
46

57
plugins {
6-
kotlin("multiplatform") version "1.8.20"
8+
val kotlinVersion = "1.9.20-Beta"
9+
kotlin("multiplatform") version kotlinVersion
710
//id("dev.petuska.npm.publish") version "2.1.1"
811
id("io.gitlab.arturbosch.detekt").version("1.23.0-RC2")
9-
id("org.jetbrains.dokka") version "1.8.10"
10-
id("org.jetbrains.kotlinx.kover") version "0.6.1"
12+
id("org.jetbrains.dokka") version "1.9.0"
13+
id("org.jetbrains.kotlinx.kover") version "0.7.3"
1114
id("maven-publish")
1215
id("signing")
1316
}
1417

1518
val defaultGroupId = "cz.sazel.sqldelight"
16-
val versionBase = "0.2.0"
19+
val versionBase = "0.3.0"
1720

1821
val localProperties = Properties().apply {
1922
try {
@@ -67,8 +70,6 @@ kotlin {
6770
dependencies {
6871
implementation(kotlin("stdlib-common"))
6972
implementation(libs.kotlin.coroutines.core)
70-
71-
7273
}
7374
}
7475
val commonTest by getting {
@@ -85,11 +86,12 @@ kotlin {
8586
}
8687
}
8788
val jsTest by getting {
88-
kover {
89-
htmlReport {
90-
onCheck.set(true)
89+
extensions.configure<KoverReportExtension> {
90+
defaults {
91+
html {
92+
onCheck = true
93+
}
9194
}
92-
isDisabled.set(false)
9395
}
9496
}
9597

@@ -220,18 +222,11 @@ val bindingsInstall = tasks.register("sqlite3BindingsInstall") {
220222
}.get()
221223
tasks["kotlinNpmInstall"].finalizedBy(bindingsInstall)
222224

223-
koverMerged {
224-
htmlReport {
225-
onCheck.set(true)
226-
}
227-
enable()
228-
}
229-
230225
detekt {
231226
buildUponDefaultConfig = true // preconfigure defaults
232227
allRules = false // activate all available (even unstable) rules.
233228
config.setFrom("$projectDir/gradle/detekt/detekt.yml") // point to your custom config defining rules to run, overwriting default behavior
234-
// baseline = file("$projectDir/config/baseline.xml") // a way of suppressing issues before introducing detekt
229+
// baseline = file("$projectDir/config/baseline.xml") // a way of suppressing issues before introducing detekt
235230
}
236231

237232
tasks.withType<Detekt>().configureEach {

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[versions]
2-
kotlin = "1.8.20"
2+
kotlin = "1.9.20-Beta"
33
kotlinCoroutines = "1.6.4"
44
schemaCrawler = "16.19.2"
55
stately = "1.2.3"
6-
node-sqlite3 = "5.1.4"
7-
sqldelight = "2.0.0-rc01"
6+
node-sqlite3 = "5.1.6"
7+
sqldelight = "2.0.0"
88

99
[libraries]
1010
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }

src/jsMain/kotlin/cz/sazel/sqldelight/node/sqlite3/SQLite3Cursor.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ internal class SQLite3Cursor(val statementInit: suspend () -> Sqlite3.Statement)
5252
if (err == null) cont.resume(Unit) else cont.resumeWithException(SQLite3JsException(err))
5353
}
5454
statement.finalize(callback)
55-
5655
}
5756
}
5857

src/jsMain/kotlin/cz/sazel/sqldelight/node/sqlite3/SQLite3Driver.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
3636
override fun endTransaction(successful: Boolean): QueryResult<Unit> = QueryResult.AsyncValue {
3737
if (enclosingTransaction == null) {
3838
val sql = if (successful) "END TRANSACTION" else "ROLLBACK TRANSACTION"
39-
suspendCoroutine { cont ->
39+
suspendCoroutine<Any?> { cont ->
4040
val callback: (Any?) -> Unit = {
4141
if (it == null || it !is Throwable) {
4242
cont.resume(it)
@@ -119,7 +119,7 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
119119
val transaction = Transaction(enclosing)
120120
this.transaction = transaction
121121
if (enclosing == null) {
122-
suspendCoroutine { cont ->
122+
suspendCoroutine<Any?> { cont ->
123123
val callback: (Any?) -> Unit = {
124124
if (it == null || it !is Throwable) {
125125
cont.resume(it)
@@ -138,20 +138,34 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
138138

139139
internal fun _endTransactionForTests(successful: Boolean) = transaction?._endTransactionForTests(successful)
140140

141+
internal suspend fun _finalizeAllStatements() {
142+
statements.onEach { statement ->
143+
suspendCoroutine<Any?> { cont ->
144+
val callback: (err: Error?) -> Unit = {
145+
if (it == null) {
146+
cont.resume(it)
147+
} else {
148+
cont.resumeWithException(SQLite3JsException(it))
149+
}
150+
}
151+
statement.value.finalize(callback)
152+
}
153+
}
154+
}
141155

142-
override fun addListener(listener: Query.Listener, queryKeys: Array<String>) {
156+
override fun addListener(vararg queryKeys: String, listener: Query.Listener) {
143157
queryKeys.forEach {
144158
listeners.getOrPut(it) { mutableSetOf() }.add(listener)
145159
}
146160
}
147161

148-
override fun removeListener(listener: Query.Listener, queryKeys: Array<String>) {
162+
override fun removeListener(vararg queryKeys: String, listener: Query.Listener) {
149163
queryKeys.forEach {
150164
listeners[it]?.remove(listener)
151165
}
152166
}
153167

154-
override fun notifyListeners(queryKeys: Array<String>) {
168+
override fun notifyListeners(vararg queryKeys: String) {
155169
queryKeys.flatMap { listeners[it].orEmpty() }
156170
.distinct()
157171
.forEach(Query.Listener::queryResultsChanged)
@@ -170,7 +184,7 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
170184
if (parameters > 0) {
171185
val bound = SQLite3PreparedStatement(parameters)
172186
binders(bound)
173-
suspendCoroutine { cont ->
187+
suspendCoroutine<Any?> { cont ->
174188
val callback: (Any?) -> Unit = {
175189
if (it == null || it !is Throwable) {
176190
cont.resume(it)

src/jsTest/kotlin/cz/sazel/sqldelight/node/sqlite3/SQLite3DriverTest.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ typealias InsertFunction = suspend (SqlPreparedStatement.() -> Unit) -> Unit
1010

1111
class SQLite3DriverTest {
1212
private val schema = object : SqlSchema<QueryResult.AsyncValue<Unit>> {
13-
override val version: Int = 1
13+
override val version = 1L
1414

1515
override fun create(driver: SqlDriver): QueryResult.AsyncValue<Unit> = QueryResult.AsyncValue {
1616
driver.execute(
@@ -40,10 +40,10 @@ class SQLite3DriverTest {
4040

4141
override fun migrate(
4242
driver: SqlDriver,
43-
oldVersion: Int,
44-
newVersion: Int,
45-
vararg callbacks: AfterVersion,
46-
) = QueryResult.AsyncValue {}
43+
oldVersion: Long,
44+
newVersion: Long,
45+
vararg callbacks: AfterVersion
46+
): QueryResult.AsyncValue<Unit> = QueryResult.AsyncValue {}
4747
}
4848

4949
private fun runTest(block: suspend (SqlDriver) -> Unit) = kotlinx.coroutines.test.runTest {
@@ -52,6 +52,7 @@ class SQLite3DriverTest {
5252
val driver = initSqlite3SqlDriver("test.db", schema = schema)
5353
println("db test.db created")
5454
block(driver)
55+
driver._finalizeAllStatements()
5556
driver.close()
5657
println("deleting db")
5758
js("require('fs').unlinkSync('test.db')")

0 commit comments

Comments
 (0)