Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ supports [sqlite3](https://www.npmjs.com/package/sqlite3) Node.js module

## Gradle set up

Pretty much it's almost the same as with https://sqldelight.github.io/sqldelight/2.0.2/js_sqlite
Pretty much it's almost the same as with https://sqldelight.github.io/sqldelight/2.1.0/js_sqlite

Initialization of SQLDelight is needed

```kotlin
plugins {
kotlin("js") version "2.1.20" // probably would work even with different one
id("app.cash.sqldelight") version "2.0.2" // for version 0.4.0 and higher
kotlin("js") version "2.2.20" // probably would work even with different one
id("app.cash.sqldelight") version "2.1.0" // for version 0.5.0 and higher
}
Expand All @@ -42,7 +42,7 @@ kotlin {
binaries.executable()
nodejs {
dependencies {
implementation("cz.sazel.sqldelight:node-sqlite3-driver-js:0.4.1")
implementation("cz.sazel.sqldelight:node-sqlite3-driver-js:0.5.0")
}
}
}
Expand Down Expand Up @@ -75,7 +75,7 @@ tasks["kotlinNpmInstall"].finalizedBy(bindingsInstall)

## Simple example

Queries are written as here - https://sqldelight.github.io/sqldelight/2.0.2/js_sqlite/#using-queries
Queries are written as here - https://sqldelight.github.io/sqldelight/2.1.0/js_sqlite/#using-queries

```kotlin
suspend fun main() {
Expand All @@ -85,19 +85,19 @@ suspend fun main() {

val playerQueries: PlayerQueries = database.playerQueries

println(playerQueries.selectAll().executeSuspendingAsList())
println(playerQueries.selectAll().awaitAsList())
// Prints [HockeyPlayer(15, "Ryan Getzlaf")]

playerQueries.insert(player_number = 10, full_name = "Corey Perry")
println(playerQueries.selectAll().executeSuspendingAsList())
println(playerQueries.selectAll().awaitAsList())
// Prints [HockeyPlayer(15, "Ryan Getzlaf"), HockeyPlayer(10, "Corey Perry")]

val player = HockeyPlayer(20, "Ronald McDonald")
playerQueries.insertFullPlayerObject(player)
}
```

Note: Please use `executeSuspendingAsList()` or `executeAsFlow()` in queries instead of `executeAsList()`
Note: Please use `awaitAsList()` or `executeAsFlow()` in queries instead of `executeAsList()`
as that API is not suspending and will throw an exception with this driver.

## Thanks
Expand Down
155 changes: 77 additions & 78 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
}

val defaultGroupId = "cz.sazel.sqldelight"
val versionBase = "0.4.0"
val versionBase = "0.5.0"

val localProperties = Properties().apply {
try {
Expand Down Expand Up @@ -47,14 +47,12 @@ repositories {
}
}

kotlin {
lateinit var publicationsFromMainHost: List<String>


js(IR) {
compilations.all {
kotlinOptions.moduleKind = "commonjs"
}
kotlin {

js(IR) {
useCommonJs()
nodejs {
kotlinNodeJsEnvSpec.version.set(libs.versions.node.js.get())
Expand Down Expand Up @@ -84,7 +82,7 @@ kotlin {
dependencies {
implementation(libs.sqldelight.runtime.js)
implementation(libs.sqldelight.async.extensions.js)
implementation(npm("sqlite3", libs.versions.node.sqlite3.get(), false))
implementation(npm("sqlite3", libs.versions.node.sqlite3.get()))
}
}
val jsTest by getting {
Expand All @@ -98,7 +96,7 @@ kotlin {
}
}

val publicationsFromMainHost = listOf(js()).map { it.name } + "kotlinMultiplatform"
publicationsFromMainHost = listOf(js()).map { it.name } + "kotlinMultiplatform"

dokka {
moduleName = "node-sqlite3-driver"
Expand All @@ -111,94 +109,95 @@ kotlin {
}
}

val javadocJar = tasks.register<Jar>("javadocJar") {
dependsOn(tasks.dokkaGenerate.get())
archiveClassifier.set("javadoc")
from(layout.buildDirectory.dir("dokka/html"))
}

publishing {
}
}

publications {
matching { it.name in publicationsFromMainHost }.all {
val targetPublication = this@all
tasks.withType<AbstractPublishToMaven>().matching { it.publication == targetPublication }
.configureEach { onlyIf { findProperty("isMainHost") == "true" } }
}
val javadocJar = tasks.register<Jar>("javadocJar") {
dependsOn(tasks.dokkaGenerate.get())
archiveClassifier.set("javadoc")
from(layout.buildDirectory.dir("dokka/html"))
}

publishing {
publications {
matching { it.name in publicationsFromMainHost }.all {
val targetPublication = this@all
tasks.withType<AbstractPublishToMaven>().matching { it.publication == targetPublication }
.configureEach { onlyIf { findProperty("isMainHost") == "true" } }
}

withType<MavenPublication> {
artifact(javadocJar)

pom {
name.set("node-sqlite3-driver")
description.set("Driver for the library SQLDelight that supports sqlite3 Node.js module")
licenses {
license {
name.set("Apache-2.0")
url.set("https://opensource.org/licenses/Apache-2.0")
}
}
url.set("https://github.com/wojta/sqldelight-node-sqlite3-driver")
issueManagement {
system.set("Github")
url.set("https://github.com/wojta/sqldelight-node-sqlite3-driver/issues")
}
scm {
connection.set("https://github.com/wojta/sqldelight-node-sqlite3-driver.git")
url.set("https://github.com/wojta/sqldelight-node-sqlite3-driver")
}
developers {
developer {
name.set("Vojtěch Sázel")
email.set("sqldelight@sazel.cz")
}
}
}
}

}
withType<MavenPublication> {
artifact(javadocJar)

repositories {
val githubUserName = System.getenv("GITHUB_USER") ?: localProperties["github.user"] as String?
if (githubUserName != null) { // Github packages repo
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/wojta/sqldelight-node-sqlite3-driver") // Github Package

credentials {
//Fetch these details from the properties file or from Environment variables
username = githubUserName
password = System.getenv("GITHUB_TOKEN") ?: localProperties["github.token"] as String?
}
pom {
name.set("node-sqlite3-driver")
description.set("Driver for the library SQLDelight that supports sqlite3 Node.js module")
licenses {
license {
name.set("Apache-2.0")
url.set("https://opensource.org/licenses/Apache-2.0")
}
}
maven { // OSS Sonatype (default)
val isSnapshot = version.toString().endsWith("SNAPSHOT")
val destination = if (!isSnapshot) {
"https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
} else "https://s01.oss.sonatype.org/content/repositories/snapshots"
url = uri(destination)
credentials {
username = System.getenv("SONATYPE_USER") ?: localProperties["sonatype.user"] as String?
password = System.getenv("SONATYPE_PASSWORD") ?: localProperties["sonatype.password"] as String?
url.set("https://github.com/wojta/sqldelight-node-sqlite3-driver")
issueManagement {
system.set("Github")
url.set("https://github.com/wojta/sqldelight-node-sqlite3-driver/issues")
}
scm {
connection.set("https://github.com/wojta/sqldelight-node-sqlite3-driver.git")
url.set("https://github.com/wojta/sqldelight-node-sqlite3-driver")
}
developers {
developer {
name.set("Vojtěch Sázel")
email.set("sqldelight@sazel.cz")
}
}
mavenLocal()
}
}

signing {
useInMemoryPgpKeys(
System.getenv("GPG_KEY_SECRET") ?: localProperties["gpg.keySecret"] as String?,
System.getenv("GPG_KEY_PASSWORD") ?: localProperties["gpg.keyPassword"] as String?
)
}

sign(publishing.publications)
repositories {
val githubUserName = System.getenv("GITHUB_USER") ?: localProperties["github.user"] as String?
if (githubUserName != null) { // Github packages repo
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/wojta/sqldelight-node-sqlite3-driver") // Github Package

credentials {
//Fetch these details from the properties file or from Environment variables
username = githubUserName
password = System.getenv("GITHUB_TOKEN") ?: localProperties["github.token"] as String?
}
}
}
maven { // OSS Sonatype (default)
val isSnapshot = version.toString().endsWith("SNAPSHOT")
val destination = if (!isSnapshot) {
"https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
} else "https://s01.oss.sonatype.org/content/repositories/snapshots"
url = uri(destination)
credentials {
username = System.getenv("SONATYPE_USER") ?: localProperties["sonatype.user"] as String?
password = System.getenv("SONATYPE_PASSWORD") ?: localProperties["sonatype.password"] as String?
}
}
mavenLocal()
}
}

signing {
useInMemoryPgpKeys(
System.getenv("GPG_KEY_SECRET") ?: localProperties["gpg.keySecret"] as String?,
System.getenv("GPG_KEY_PASSWORD") ?: localProperties["gpg.keyPassword"] as String?
)

sign(publishing.publications)
}

// workaround for missing sqlite3 bindings
val bindingsInstall = tasks.register("sqlite3BindingsInstall") {
doFirst {
Expand Down
9 changes: 4 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
detekt = "1.23.7"
dokka = "2.0.0"
kotlin = "2.1.20-Beta1"
kotlinCoroutines = "1.10.1"
kotlin = "2.2.20"
kotlinCoroutines = "1.10.2"
kover = "0.9.1"
node-sqlite3 = "5.1.7"
node-js = "22.13.0"
sqldelight = "2.0.2"
sqldelight = "2.1.0"

[libraries]
kotlin-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinCoroutines" }
Expand All @@ -18,6 +18,5 @@ sqldelight-runtime-js = { module = "app.cash.sqldelight:runtime-js", version.ref
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-js = { id = "org.jetbrains.kotlin.js", version.ref = "kotlin" }
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
sqldelight = { id = "app.cash.sqldelight", version.ref = "sqldelight" }
sqldelight = { id = "app.cash.sqldelight", version.ref = "sqldelight" }
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
if (enclosingTransaction == null) {
statements.onEach { it.value.finalizeSuspending() }
val sql = if (successful) "END TRANSACTION" else "ROLLBACK TRANSACTION"
suspendCoroutine<Any?> { cont ->
suspendCoroutine { cont ->
val callback: (Any?) -> Unit = {
if (it == null || it !is Throwable) {
cont.resume(it)
Expand Down Expand Up @@ -136,7 +136,7 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
val transaction = Transaction(enclosing)
this.transaction = transaction
if (enclosing == null) {
suspendCoroutine<Any?> { cont ->
suspendCoroutine { cont ->
val callback: (Any?) -> Unit = {
if (it == null || it !is Throwable) {
cont.resume(it)
Expand Down Expand Up @@ -186,7 +186,7 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
if (parameters > 0) {
val bound = SQLite3PreparedStatement(parameters)
binders(bound)
suspendCoroutine<Any?> { cont ->
suspendCoroutine { cont ->
val callback: (Any?) -> Unit = {
if (it == null || it !is Throwable) {
cont.resume(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlinx.coroutines.flow.toList
* Use this instead of non-async method [Query.executeAsList].
* @return The result set of the underlying SQL statement as a list of RowType.
*/
@Deprecated("Use awaitAsList() instead", ReplaceWith("awaitAsList()"))
suspend fun <T : Any> Query<T>.executeSuspendingAsList(): List<T> =
executeAsFlow().toList(mutableListOf())

Expand Down
Loading
Loading