Skip to content

Commit

Permalink
Make JVM samples consistent with other platforms (#5374)
Browse files Browse the repository at this point in the history
The JVM code samples do not use the `PRAGMA user_version`-based
migration logic, which is a bit misleading because samples for other
platforms do.

The inconsistency is particularly visible in the Multiplatform case,
where the android and native samples will set `user_version=1`, but the
JVM sample will produce `user_version=0`.
  • Loading branch information
pm47 committed Jul 25, 2024
1 parent 95571cc commit 4325311
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
8 changes: 3 additions & 5 deletions docs/jvm_sqlite/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ your project.
}
```

An instance of the driver can be constructed as shown below. The constructor accepts a JDBC
An instance of the driver can be constructed as shown below. The constructor accepts a JDBC
connection string that specifies the location of the database file. The `IN_MEMORY`
constant can also be passed to the constructor to create an in-memory database.

=== "On-Disk"
```kotlin
val driver: SqlDriver = JdbcSqliteDriver("jdbc:sqlite:test.db")
Database.Schema.create(driver)
val driver: SqlDriver = JdbcSqliteDriver("jdbc:sqlite:test.db", Properties(), Database.Schema)
```
=== "In-Memory"
```kotlin
val driver: SqlDriver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
Database.Schema.create(driver)
val driver: SqlDriver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY, Properties(), Database.Schema)
```

{% include 'common/index_queries.md' %}
19 changes: 9 additions & 10 deletions docs/multiplatform_sqlite/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ Each target platform has its own driver implementation.

=== "Kotlin"
```kotlin
kotlin {
kotlin {
sourceSets.androidMain.dependencies {
implementation("app.cash.sqldelight:android-driver:{{ versions.sqldelight }}")
}

// or iosMain, windowsMain, etc.
sourceSets.nativeMain.dependencies {
implementation("app.cash.sqldelight:native-driver:{{ versions.sqldelight }}")
}

sourceSets.jvmMain.dependencies {
implementation("app.cash.sqldelight:sqlite-driver:{{ versions.sqldelight }}")
}
}
```
=== "Groovy"
```groovy
kotlin {
kotlin {
sourceSets.androidMain.dependencies {
implementation "app.cash.sqldelight:android-driver:{{ versions.sqldelight }}"
}

// or iosMain, windowsMain, etc.
sourceSets.nativeMain.dependencies {
implementation "app.cash.sqldelight:native-driver:{{ versions.sqldelight }}"
}

sourceSets.jvmMain.dependencies {
implementation "app.cash.sqldelight:sqlite-driver:{{ versions.sqldelight }}"
}
Expand All @@ -44,7 +44,7 @@ Each target platform has its own driver implementation.

## Constructing Driver Instances

Create a common factory class or method to obtain a `SqlDriver` instance.
Create a common factory class or method to obtain a `SqlDriver` instance.

```kotlin title="src/commonMain/kotlin"
import com.example.Database
Expand All @@ -67,7 +67,7 @@ Then implement this for each target platform:
```kotlin
actual class DriverFactory(private val context: Context) {
actual fun createDriver(): SqlDriver {
return AndroidSqliteDriver(Database.Schema, context, "test.db")
return AndroidSqliteDriver(Database.Schema, context, "test.db")
}
}
```
Expand All @@ -83,8 +83,7 @@ Then implement this for each target platform:
```kotlin
actual class DriverFactory {
actual fun createDriver(): SqlDriver {
val driver: SqlDriver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
Database.Schema.create(driver)
val driver: SqlDriver = JdbcSqliteDriver("jdbc:sqlite:test.db", Properties(), Database.Schema)
return driver
}
}
Expand Down

0 comments on commit 4325311

Please sign in to comment.