mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-06 07:29:10 +00:00
Add JVM target to shared module
This commit is contained in:
@@ -39,6 +39,8 @@ object Dependencies {
|
|||||||
const val ktorIos = "io.ktor:ktor-client-ios:$version"
|
const val ktorIos = "io.ktor:ktor-client-ios:$version"
|
||||||
const val ktorJson = "io.ktor:ktor-client-json:$version"
|
const val ktorJson = "io.ktor:ktor-client-json:$version"
|
||||||
const val ktorSerialization = "io.ktor:ktor-client-serialization:$version"
|
const val ktorSerialization = "io.ktor:ktor-client-serialization:$version"
|
||||||
|
|
||||||
|
const val slf4j = "org.slf4j:slf4j-simple:1.7.30"
|
||||||
}
|
}
|
||||||
|
|
||||||
object Serialization {
|
object Serialization {
|
||||||
@@ -51,6 +53,7 @@ object Dependencies {
|
|||||||
const val sqlDelightCoroutines = "com.squareup.sqldelight:coroutines-extensions:$version"
|
const val sqlDelightCoroutines = "com.squareup.sqldelight:coroutines-extensions:$version"
|
||||||
const val sqlDelightAndroid = "com.squareup.sqldelight:android-driver:$version"
|
const val sqlDelightAndroid = "com.squareup.sqldelight:android-driver:$version"
|
||||||
const val sqlDelightNative = "com.squareup.sqldelight:native-driver:$version"
|
const val sqlDelightNative = "com.squareup.sqldelight:native-driver:$version"
|
||||||
|
const val sqlDelightSQLite = "com.squareup.sqldelight:sqlite-driver:$version"
|
||||||
}
|
}
|
||||||
|
|
||||||
object AboutLibraries {
|
object AboutLibraries {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ repositories {
|
|||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
android()
|
android()
|
||||||
|
jvm()
|
||||||
|
|
||||||
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
|
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
|
||||||
|
|
||||||
@@ -85,6 +86,19 @@ kotlin {
|
|||||||
implementation(Dependencies.SQLDelight.sqlDelightNative)
|
implementation(Dependencies.SQLDelight.sqlDelightNative)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val jvmMain by getting {
|
||||||
|
dependencies {
|
||||||
|
// Ktor
|
||||||
|
implementation(Dependencies.Ktor.ktorOkhttp)
|
||||||
|
implementation(Dependencies.Ktor.slf4j)
|
||||||
|
|
||||||
|
// SqlDelight
|
||||||
|
implementation(Dependencies.SQLDelight.sqlDelightSQLite)
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
implementation(Dependencies.Misc.jsoup)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package net.underdesk.circolapp.shared
|
||||||
|
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
||||||
|
actual object PlatformDispatcher {
|
||||||
|
actual val IO = Dispatchers.IO
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package net.underdesk.circolapp.shared.data
|
||||||
|
|
||||||
|
import com.squareup.sqldelight.db.SqlDriver
|
||||||
|
import com.squareup.sqldelight.sqlite.driver.JdbcSqliteDriver
|
||||||
|
|
||||||
|
actual class DatabaseDriverFactory {
|
||||||
|
actual fun createDriver(): SqlDriver {
|
||||||
|
return JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY + "circolapp.db")
|
||||||
|
.also {
|
||||||
|
val currentVer = getVersion(it)
|
||||||
|
if (currentVer == 0) {
|
||||||
|
AppDatabase.Schema.create(it)
|
||||||
|
setVersion(it, 1)
|
||||||
|
} else {
|
||||||
|
val schemaVer: Int = AppDatabase.Schema.version
|
||||||
|
if (schemaVer > currentVer) {
|
||||||
|
AppDatabase.Schema.migrate(it, currentVer, schemaVer)
|
||||||
|
setVersion(it, schemaVer)
|
||||||
|
println("init: migrated from $currentVer to $schemaVer")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getVersion(driver: SqlDriver): Int {
|
||||||
|
val sqlCursor = driver.executeQuery(null, "PRAGMA user_version;", 0, null)
|
||||||
|
return sqlCursor.getLong(0)!!.toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setVersion(driver: SqlDriver, version: Int) {
|
||||||
|
driver.execute(null, String.format("PRAGMA user_version = %d;", version), 0, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user