diff --git a/BankingPersistence/build.gradle.kts b/BankingPersistence/build.gradle.kts new file mode 100644 index 0000000..0f13d0d --- /dev/null +++ b/BankingPersistence/build.gradle.kts @@ -0,0 +1,108 @@ +plugins { + alias(libs.plugins.kotlinMultiplatform) + + alias(libs.plugins.androidLibrary) + + alias(libs.plugins.sqldelight) +} + + +kotlin { + jvmToolchain(11) + + jvm() + + js { + moduleName = "BankingPersistence" + binaries.executable() + + browser() + } + + androidTarget { + + } + + + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64() + ).forEach { iosTarget -> + iosTarget.binaries.framework { + baseName = "ComposeApp" + isStatic = false + } + } + + applyDefaultHierarchyTemplate() + + + sourceSets { + commonMain.dependencies { + implementation(libs.sqldelight.runtime) + implementation(libs.sqldelight.coroutines.extensions) + implementation(libs.sqldelight.paging.extensions) + } + + commonTest.dependencies { + implementation(libs.kotlin.test) + + implementation(libs.coroutines.test) + } + + androidMain.dependencies { + implementation(libs.sqldelight.android.driver) + } + + iosMain.dependencies { + implementation(libs.sqldelight.native.driver) + } + + jvmTest.dependencies { + implementation(libs.kotlin.test.junit) + } + + jvmMain.dependencies { + implementation(libs.sqldelight.sqlite.driver) + } + } +} + + +sqldelight { + databases { + create("BankmeisterDb") { + packageName.set("net.codinux.banking.persistence") + generateAsync = true + + schemaOutputDirectory = file("src/commonMain/sqldelight/databases") + } + } +} + + +android { + namespace = "net.codinux.banking.persistence" + compileSdk = libs.versions.android.compileSdk.get().toInt() + +// sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") + + defaultConfig { + minSdk = libs.versions.android.minSdk.get().toInt() + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false +// proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } +} \ No newline at end of file diff --git a/BankingPersistence/src/androidMain/kotlin/net/codinux/banking/persistence/AndroidContext.kt b/BankingPersistence/src/androidMain/kotlin/net/codinux/banking/persistence/AndroidContext.kt new file mode 100644 index 0000000..fc52aa3 --- /dev/null +++ b/BankingPersistence/src/androidMain/kotlin/net/codinux/banking/persistence/AndroidContext.kt @@ -0,0 +1,7 @@ +package net.codinux.banking.persistence + +import android.content.Context + +object AndroidContext { + lateinit var applicationContext: Context +} \ No newline at end of file diff --git a/BankingPersistence/src/androidMain/kotlin/net/codinux/banking/persistence/BankingRepository.android.kt b/BankingPersistence/src/androidMain/kotlin/net/codinux/banking/persistence/BankingRepository.android.kt new file mode 100644 index 0000000..a573509 --- /dev/null +++ b/BankingPersistence/src/androidMain/kotlin/net/codinux/banking/persistence/BankingRepository.android.kt @@ -0,0 +1,10 @@ +package net.codinux.banking.persistence + +import app.cash.sqldelight.async.coroutines.synchronous +import app.cash.sqldelight.db.QueryResult +import app.cash.sqldelight.db.SqlDriver +import app.cash.sqldelight.db.SqlSchema +import app.cash.sqldelight.driver.android.AndroidSqliteDriver + +actual fun createSqlDriverDriver(dbName: String, schema: SqlSchema>, version: Long): SqlDriver = + AndroidSqliteDriver(schema.synchronous(), AndroidContext.applicationContext, dbName) \ No newline at end of file diff --git a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepositoryNewStart.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepositoryNewStart.kt new file mode 100644 index 0000000..b4b5d3a --- /dev/null +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepositoryNewStart.kt @@ -0,0 +1,16 @@ +package net.codinux.banking.persistence + +import app.cash.sqldelight.db.QueryResult +import app.cash.sqldelight.db.SqlDriver +import app.cash.sqldelight.db.SqlSchema + +expect fun createSqlDriverDriver(dbName: String, schema: SqlSchema>, version: Long): SqlDriver + + +class BankingRepositoryNewStart { + + private val schema = BankmeisterDb.Schema + + private val sqlDriver = createSqlDriverDriver("Bankmeister.db", schema, 1L) + +} \ No newline at end of file diff --git a/BankingPersistence/src/iosMain/kotlin/net/codinux/banking/persistence/BankingRepository.ios.kt b/BankingPersistence/src/iosMain/kotlin/net/codinux/banking/persistence/BankingRepository.ios.kt new file mode 100644 index 0000000..1480a6d --- /dev/null +++ b/BankingPersistence/src/iosMain/kotlin/net/codinux/banking/persistence/BankingRepository.ios.kt @@ -0,0 +1,10 @@ +package net.codinux.banking.persistence + +import app.cash.sqldelight.async.coroutines.synchronous +import app.cash.sqldelight.db.QueryResult +import app.cash.sqldelight.db.SqlDriver +import app.cash.sqldelight.db.SqlSchema +import app.cash.sqldelight.driver.native.NativeSqliteDriver + +actual fun createSqlDriverDriver(dbName: String, schema: SqlSchema>, version: Long): SqlDriver = + NativeSqliteDriver(schema.synchronous(), dbName) \ No newline at end of file diff --git a/BankingPersistence/src/jsMain/kotlin/net/codinux/banking/persistence/BankingRepository.js.kt b/BankingPersistence/src/jsMain/kotlin/net/codinux/banking/persistence/BankingRepository.js.kt new file mode 100644 index 0000000..e9fa8f1 --- /dev/null +++ b/BankingPersistence/src/jsMain/kotlin/net/codinux/banking/persistence/BankingRepository.js.kt @@ -0,0 +1,9 @@ +package net.codinux.banking.persistence + +import app.cash.sqldelight.db.QueryResult +import app.cash.sqldelight.db.SqlDriver +import app.cash.sqldelight.db.SqlSchema + +actual fun createSqlDriverDriver(dbName: String, schema: SqlSchema>, version: Long): SqlDriver { + throw NotImplementedError("TODO") +} \ No newline at end of file diff --git a/BankingPersistence/src/jvmMain/kotlin/net/codinux/banking/persistence/BankingRepository.jvm.kt b/BankingPersistence/src/jvmMain/kotlin/net/codinux/banking/persistence/BankingRepository.jvm.kt new file mode 100644 index 0000000..f2d5d80 --- /dev/null +++ b/BankingPersistence/src/jvmMain/kotlin/net/codinux/banking/persistence/BankingRepository.jvm.kt @@ -0,0 +1,22 @@ +package net.codinux.banking.persistence + +import app.cash.sqldelight.async.coroutines.synchronous +import app.cash.sqldelight.db.QueryResult +import app.cash.sqldelight.db.SqlDriver +import app.cash.sqldelight.db.SqlSchema +import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver +import java.io.File + +actual fun createSqlDriverDriver(dbName: String, schema: SqlSchema>, version: Long): SqlDriver { + val dbDir = File("data/db").also { it.mkdirs() } + + return JdbcSqliteDriver("jdbc:sqlite:data/db/$dbName").also { driver -> + schema.synchronous().also { schema -> + if (File(dbDir, dbName).exists() == false) { + schema.create(driver) + } + + schema.migrate(driver, schema.version, version) + } + } +} \ No newline at end of file