Skip to content

Commit 3da928a

Browse files
committed
Merge branch 'feature/sqlite-jvm'
2 parents 7a2bd9e + 9fd753e commit 3da928a

File tree

18 files changed

+619
-33
lines changed

18 files changed

+619
-33
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,16 @@ Short deep‑dive posts covering Kotlin/Native, FFI, and Rust ↔ Kotlin interop
6565

6666
### Next Steps (contributions are welcome)
6767

68-
- Create and publish sqlx4k-gradle-plugin.
68+
- Create and publish sqlx4k-gradle-plugin
6969
- Pure Kotlin implementation for `ConnectionPool`
7070
- Validate queries at compile time (avoid runtime errors)
7171
- Syntax checking is already supported (using the `@Query` annotation) ✅
7272
- Validate queries by accessing the DB schema ✅
7373
- Validate query literal types (type check query parameters)
74-
- Add support for SQLite JVM target.
74+
- Add support for SQLite JVM target
7575
- WASM support (?).
76-
- Pure Kotlin implementation for PostgreSQL.
77-
- Pure Kotlin implementation for MySQL.
78-
- Pure Kotlin implementation for SQLite.
76+
- Pure Kotlin implementation for PostgreSQL
77+
- Pure Kotlin implementation for MySQL
7978

8079
### Supported Databases
8180

@@ -592,7 +591,7 @@ SQLDelight integration for type-safe SQL queries with sqlx4k.
592591

593592
## Supported Targets
594593

595-
- jvm (only PostgreSQL and MySQL are supported at the moment)
594+
- jvm
596595
- iosArm64
597596
- iosSimulatorArm64
598597
- androidNativeX64
@@ -734,6 +733,8 @@ sqlx4k stands on the shoulders of excellent open-source projects:
734733
- https://github.com/pgjdbc/r2dbc-postgresql
735734
- MySQL: r2dbc-mysql
736735
- https://github.com/asyncer-io/r2dbc-mysql
736+
- SQLite: rsqlite-jdbc
737+
- https://github.com/xerial/sqlite-jdbc
737738

738739
- Build-time tooling
739740
- JSqlParser — used by the code generator to parse @Query SQL at build time for syntax validation.

examples/sqlite/src/jvmMain/kotlin/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fun main() = runBlocking {
1010
.build()
1111

1212
val db = sqlite(
13-
url = "sqlite::memory:",
13+
url = "sqlite://test.db",
1414
options = options
1515
)
1616

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jsqlparser = "5.3"
3636
calcite = "1.40.0"
3737
# https://github.com/smyrgeorge/log4k
3838
log4k = "1.1.2"
39+
# https://github.com/xerial/sqlite-jdbc
40+
sqlite-jdbc = "3.50.3.0"
3941

4042
[libraries]
4143
gradle-kotlin-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
@@ -55,6 +57,7 @@ r2dbc-postgresql = { module = "org.postgresql:r2dbc-postgresql", version.ref = "
5557
jsqlparser = { module = "com.github.jsqlparser:jsqlparser", version.ref = "jsqlparser" }
5658
calcite-core = { module = "org.apache.calcite:calcite-core", version.ref = "calcite" }
5759
log4k-slf4j = { module = "io.github.smyrgeorge:log4k-slf4j", version.ref = "log4k" }
60+
sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version.ref = "sqlite-jdbc" }
5861

5962
[plugins]
6063
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }

sqlx4k-mysql/src/jvmMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import kotlin.time.Duration
3131
import kotlin.time.toJavaDuration
3232
import io.r2dbc.pool.ConnectionPool as R2dbcConnectionPool
3333
import io.r2dbc.spi.Connection as R2dbcConnection
34-
34+
import io.r2dbc.spi.Result as R2dbcResultSet
3535

3636
/**
3737
* The `MySQL` class provides a driver implementation for interacting with a MySQL database.
@@ -357,7 +357,7 @@ class MySQL(
357357
}.build()
358358
}
359359

360-
private suspend fun io.r2dbc.spi.Result.toResultSet(): ResultSet {
360+
private suspend fun R2dbcResultSet.toResultSet(): ResultSet {
361361
fun Row.toRow(): ResultSet.Row {
362362
val columns = metadata.columnMetadatas.mapIndexed { i, c ->
363363
ResultSet.Row.Column(

sqlx4k-postgres/src/jvmMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQLImpl.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import kotlin.time.Duration.Companion.milliseconds
2525
import io.r2dbc.pool.ConnectionPool as R2dbcConnectionPool
2626
import io.r2dbc.postgresql.api.Notification as R2dbcNotification
2727
import io.r2dbc.spi.Connection as R2dbcConnection
28+
import io.r2dbc.spi.Result as R2dbcResultSet
2829

2930
class PostgreSQLImpl(
3031
private val connectionFactory: PostgresqlConnectionFactory,
@@ -365,7 +366,7 @@ class PostgreSQLImpl(
365366
get() = EmptyCoroutineContext
366367
}
367368

368-
private suspend fun io.r2dbc.spi.Result.toResultSet(): ResultSet {
369+
private suspend fun R2dbcResultSet.toResultSet(): ResultSet {
369370
fun Row.toRow(): ResultSet.Row {
370371
val columns = metadata.columnMetadatas.mapIndexed { i, c ->
371372
ResultSet.Row.Column(

sqlx4k-sqlite/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ kotlin {
2222
implementation(libs.kotlinx.io.core)
2323
}
2424
}
25-
// No jvmMain dependencies for SQLite; JVM is not supported yet.
25+
val jvmMain by getting {
26+
dependencies {
27+
implementation(libs.sqlite.jdbc)
28+
}
29+
}
2630
}
2731
}

0 commit comments

Comments
 (0)