Skip to content

Commit

Permalink
Added support for SQLite.
Browse files Browse the repository at this point in the history
  • Loading branch information
smyrgeorge committed Aug 25, 2024
1 parent 00db39f commit 30bf1c1
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 13 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ _In the future, we may provide a pure Kotlin driver implementation._

The project is in a very early stage; thus, breaking changes and bugs should be expected.

Currently, the driver only supports
Currently, the driver supports:

- `PostgreSQL`
- `MySQL`
- `SQLite` (in progress)
- `SQLite`

## Usage

```kotlin
implementation("io.github.smyrgeorge:sqlx4k-postgres:x.y.z")
// or for MySQL
implementation("io.github.smyrgeorge:sqlx4k-mysql:x.y.z")
// or for SQLite
implementation("io.github.smyrgeorge:sqlx4k-sqlite:x.y.z")
```

## Why not a pure kotlin implementation?
Expand Down Expand Up @@ -71,6 +73,11 @@ val db = MySQL(
database = "test",
maxConnections = 10 // set the max-pool-size here
)

val db = SQLite(
database = "test.db",
maxConnections = 10
)
```

### Named parameters
Expand Down Expand Up @@ -124,7 +131,7 @@ db.listen("chan0") { notification: Postgres.Notification ->

- [x] PostgreSQL
- [x] MySQL
- [ ] SQLite
- [x] SQLite
- [x] Transactions
- [x] Named parameters
- [ ] Check for SQL injections
Expand Down Expand Up @@ -154,9 +161,28 @@ rustup target add x86_64-unknown-linux-gnu
Then, run the build.

```shell
# will build only for macosArm64 target
./gradlew build
```

You can also build for specific targets.

```shell
./gradlew build -Ptargets=macosArm64,macosArm64
```

To build for all available target run:

```shell
./gradlew build -Ptargets=all
```

## Publishing

```shell
./gradlew publishAllPublicationsToMavenCentralRepository -Ptargets=all
```

## Run

First you need to run start-up the postgres instance.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = "io.github.smyrgeorge"
version = "0.8.0"
version = "0.9.0"

plugins {
// https://plugins.gradle.org/plugin/org.jetbrains.kotlin.multiplatform
Expand Down
9 changes: 7 additions & 2 deletions sqlx4k-mysql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ private val cargo: String
?.absolutePath
?: throw GradleException("Rust cargo binary is required to build project but it wasn't found.")

val chosenTargets = (properties["targets"] as? String)?.split(",")
?: listOf("macosArm64") // For local development.
val chosenTargets = (properties["targets"] as? String)
?.let {
when (it) {
"all" -> listOf("iosArm64", "androidNativeX64", "macosArm64", "macosX64", "linuxArm64", "linuxX64")
else -> it.split(",").map { t -> t.trim() }
}
} ?: listOf("macosArm64") // For local development.

kotlin {
fun KotlinNativeTarget.rust(target: String, useCross: Boolean = false) {
Expand Down
2 changes: 1 addition & 1 deletion sqlx4k-mysql/rust_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ sqlx = { version = "0.8.1", features = [

[build-dependencies]
# https://crates.io/crates/cbindgen
cbindgen = "0.26.0"
cbindgen = "0.27.0"
9 changes: 7 additions & 2 deletions sqlx4k-postgres/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ private val cargo: String
?.absolutePath
?: throw GradleException("Rust cargo binary is required to build project but it wasn't found.")

val chosenTargets = (properties["targets"] as? String)?.split(",")
?: listOf("macosArm64") // For local development.
val chosenTargets = (properties["targets"] as? String)
?.let {
when (it) {
"all" -> listOf("iosArm64", "androidNativeX64", "macosArm64", "macosX64", "linuxArm64", "linuxX64")
else -> it.split(",").map { t -> t.trim() }
}
} ?: listOf("macosArm64") // For local development.

kotlin {
fun KotlinNativeTarget.rust(target: String, useCross: Boolean = false) {
Expand Down
2 changes: 1 addition & 1 deletion sqlx4k-postgres/rust_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ sqlx = { version = "0.8.1", features = [

[build-dependencies]
# https://crates.io/crates/cbindgen
cbindgen = "0.26.0"
cbindgen = "0.27.0"
9 changes: 7 additions & 2 deletions sqlx4k-sqlite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ private val cargo: String
?.absolutePath
?: throw GradleException("Rust cargo binary is required to build project but it wasn't found.")

val chosenTargets = (properties["targets"] as? String)?.split(",")
?: listOf("macosArm64") // For local development.
val chosenTargets = (properties["targets"] as? String)
?.let {
when (it) {
"all" -> listOf("iosArm64", "androidNativeX64", "macosArm64", "macosX64", "linuxArm64", "linuxX64")
else -> it.split(",").map { t -> t.trim() }
}
} ?: listOf("macosArm64") // For local development.

kotlin {
fun KotlinNativeTarget.rust(target: String, useCross: Boolean = false) {
Expand Down
2 changes: 1 addition & 1 deletion sqlx4k-sqlite/rust_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ sqlx = { version = "0.8.1", features = [

[build-dependencies]
# https://crates.io/crates/cbindgen
cbindgen = "0.26.0"
cbindgen = "0.27.0"

0 comments on commit 30bf1c1

Please sign in to comment.