From 3fdd367bfacefec3e2b1923306b0a25bef33b0f9 Mon Sep 17 00:00:00 2001 From: Tamim Attafi Date: Sun, 24 Mar 2024 19:40:08 +0700 Subject: [PATCH] fix: flow of a single element doesn't throw error when the element doesn't exist #3 Fixes #3 --- README.md | 4 ++-- .../com/attafitamim/kabin/publish/PublishConventions.kt | 2 +- .../kabin/compiler/sql/generator/dao/DaoGenerator.kt | 2 +- .../kotlin/com/attafitamim/kabin/core/dao/KabinDao.kt | 6 +++--- .../kotlin/com/attafitamim/kabin/Platform.android.kt | 7 ------- .../commonMain/kotlin/com/attafitamim/kabin/Greeting.kt | 9 --------- .../commonMain/kotlin/com/attafitamim/kabin/Platform.kt | 7 ------- .../kotlin/com/attafitamim/kabin/local/Playground.kt | 4 +--- .../iosMain/kotlin/com/attafitamim/kabin/Platform.ios.kt | 9 --------- .../jsMain/kotlin/com/attafitamim/kabin/Platform.js.kt | 7 ------- .../jvmMain/kotlin/com/attafitamim/kabin/Platform.jvm.kt | 7 ------- .../kotlin/com/attafitamim/kabin/Platform.wasmJs.kt | 8 -------- 12 files changed, 8 insertions(+), 64 deletions(-) delete mode 100644 sample/shared/src/androidMain/kotlin/com/attafitamim/kabin/Platform.android.kt delete mode 100644 sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/Greeting.kt delete mode 100644 sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/Platform.kt delete mode 100644 sample/shared/src/iosMain/kotlin/com/attafitamim/kabin/Platform.ios.kt delete mode 100644 sample/shared/src/jsMain/kotlin/com/attafitamim/kabin/Platform.js.kt delete mode 100644 sample/shared/src/jvmMain/kotlin/com/attafitamim/kabin/Platform.jvm.kt delete mode 100644 sample/shared/src/wasmJsMain/kotlin/com/attafitamim/kabin/Platform.wasmJs.kt diff --git a/README.md b/README.md index 05b621b..2e134ef 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Kabin Release](https://img.shields.io/github/release/tamimattafi/kabin.svg?style=for-the-badge&color=green)](https://github.com/tamimattafi/kabin/releases) +[![Kabin Release](https://img.shields.io/github/release/tamimattafi/kabin.svg?style=for-the-badge&color=darkgreen)](https://github.com/tamimattafi/kabin/releases) [![Kotlin](https://img.shields.io/github/languages/top/tamimattafi/kabin.svg?style=for-the-badge&color=blueviolet)](https://kotlinlang.org/) [![License Apache 2.0](https://img.shields.io/github/license/tamimattafi/kabin.svg?style=for-the-badge&color=purple)](https://github.com/tamimattafi/kabin/blob/main/LICENSE) @@ -75,7 +75,7 @@ For more advanced topics, read [Room](https://developer.android.com/training/dat ## Installation Latest Kabin version -[![Kabin Release](https://img.shields.io/github/release/tamimattafi/kabin.svg?style=for-the-badge&color=green)](https://github.com/tamimattafi/kabin/releases) +[![Kabin Release](https://img.shields.io/github/release/tamimattafi/kabin.svg?style=for-the-badge&color=darkgreen)](https://github.com/tamimattafi/kabin/releases) Add `common` modules to your `sourceSet`: ```kotlin diff --git a/convention/publishing/src/main/kotlin/com/attafitamim/kabin/publish/PublishConventions.kt b/convention/publishing/src/main/kotlin/com/attafitamim/kabin/publish/PublishConventions.kt index da9e79a..46b5b8f 100644 --- a/convention/publishing/src/main/kotlin/com/attafitamim/kabin/publish/PublishConventions.kt +++ b/convention/publishing/src/main/kotlin/com/attafitamim/kabin/publish/PublishConventions.kt @@ -10,7 +10,7 @@ import org.gradle.api.publish.maven.MavenPomScm class PublishConventions : Plugin { - private val version = "0.1.0-alpha01" + private val version = "0.1.0-alpha02" private val group = "com.attafitamim.kabin" override fun apply(project: Project) { diff --git a/library/compiler/src/jvmMain/kotlin/com/attafitamim/kabin/compiler/sql/generator/dao/DaoGenerator.kt b/library/compiler/src/jvmMain/kotlin/com/attafitamim/kabin/compiler/sql/generator/dao/DaoGenerator.kt index 57659dc..39c55e6 100644 --- a/library/compiler/src/jvmMain/kotlin/com/attafitamim/kabin/compiler/sql/generator/dao/DaoGenerator.kt +++ b/library/compiler/src/jvmMain/kotlin/com/attafitamim/kabin/compiler/sql/generator/dao/DaoGenerator.kt @@ -934,7 +934,7 @@ class DaoGenerator( is DataTypeSpec.DataType.Data -> if (type.nestedTypeSpec.isNullable) { "asFlowIONullable" } else { - "asFlowIONotNull" + "asFlowIO" } is DataTypeSpec.DataType.Stream -> { diff --git a/library/core/src/commonMain/kotlin/com/attafitamim/kabin/core/dao/KabinDao.kt b/library/core/src/commonMain/kotlin/com/attafitamim/kabin/core/dao/KabinDao.kt index 5c01857..3ff2770 100644 --- a/library/core/src/commonMain/kotlin/com/attafitamim/kabin/core/dao/KabinDao.kt +++ b/library/core/src/commonMain/kotlin/com/attafitamim/kabin/core/dao/KabinDao.kt @@ -7,7 +7,7 @@ import app.cash.sqldelight.SuspendingTransactionWithReturn import app.cash.sqldelight.SuspendingTransactionWithoutReturn import app.cash.sqldelight.coroutines.asFlow import app.cash.sqldelight.coroutines.mapToList -import app.cash.sqldelight.coroutines.mapToOneNotNull +import app.cash.sqldelight.coroutines.mapToOne import app.cash.sqldelight.coroutines.mapToOneOrNull import com.attafitamim.kabin.core.utils.IO import com.attafitamim.kabin.core.utils.awaitAll @@ -53,8 +53,8 @@ interface KabinDao { fun Query.asFlowIONullable(): Flow = asFlow().mapToOneOrNull(Dispatchers.IO) - fun Query.asFlowIONotNull(): Flow = - asFlow().mapToOneNotNull(Dispatchers.IO) + fun Query.asFlowIO(): Flow = + asFlow().mapToOne(Dispatchers.IO) fun Flow.mapIO(transform: suspend (value: T) -> R): Flow = map { value -> withContextIO { diff --git a/sample/shared/src/androidMain/kotlin/com/attafitamim/kabin/Platform.android.kt b/sample/shared/src/androidMain/kotlin/com/attafitamim/kabin/Platform.android.kt deleted file mode 100644 index f6fa242..0000000 --- a/sample/shared/src/androidMain/kotlin/com/attafitamim/kabin/Platform.android.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.attafitamim.kabin - -class AndroidPlatform : Platform { - override val name: String = "Android ${android.os.Build.VERSION.SDK_INT}" -} - -actual fun getPlatform(): Platform = AndroidPlatform() diff --git a/sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/Greeting.kt b/sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/Greeting.kt deleted file mode 100644 index 2d97957..0000000 --- a/sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/Greeting.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.attafitamim.kabin - -class Greeting { - private val platform: Platform = getPlatform() - - fun greet(): String { - return "Hello, ${platform.name}!" - } -} \ No newline at end of file diff --git a/sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/Platform.kt b/sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/Platform.kt deleted file mode 100644 index 5e7aaf0..0000000 --- a/sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/Platform.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.attafitamim.kabin - -interface Platform { - val name: String -} - -expect fun getPlatform(): Platform diff --git a/sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/local/Playground.kt b/sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/local/Playground.kt index 5371b48..aaa8b86 100644 --- a/sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/local/Playground.kt +++ b/sample/shared/src/commonMain/kotlin/com/attafitamim/kabin/local/Playground.kt @@ -14,15 +14,13 @@ import com.attafitamim.kabin.local.entities.data.CarPurchase import com.attafitamim.kabin.local.entities.data.Gender import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.IO -import kotlinx.coroutines.Job import kotlinx.coroutines.launch class Playground( private val configuration: KabinDatabaseConfiguration ) { - val scope = CoroutineScope(Job() + Dispatchers.IO) + val scope = CoroutineScope(Dispatchers.Default) private val database: SampleDatabase by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { SampleDatabase::class.newInstance( configuration, diff --git a/sample/shared/src/iosMain/kotlin/com/attafitamim/kabin/Platform.ios.kt b/sample/shared/src/iosMain/kotlin/com/attafitamim/kabin/Platform.ios.kt deleted file mode 100644 index 4f25f70..0000000 --- a/sample/shared/src/iosMain/kotlin/com/attafitamim/kabin/Platform.ios.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.attafitamim.kabin - -import platform.UIKit.UIDevice - -class IOSPlatform: Platform { - override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion -} - -actual fun getPlatform(): Platform = IOSPlatform() diff --git a/sample/shared/src/jsMain/kotlin/com/attafitamim/kabin/Platform.js.kt b/sample/shared/src/jsMain/kotlin/com/attafitamim/kabin/Platform.js.kt deleted file mode 100644 index c100d9b..0000000 --- a/sample/shared/src/jsMain/kotlin/com/attafitamim/kabin/Platform.js.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.attafitamim.kabin - -class JSPlatform: Platform { - override val name: String = "JS" -} - -actual fun getPlatform(): Platform = JSPlatform() diff --git a/sample/shared/src/jvmMain/kotlin/com/attafitamim/kabin/Platform.jvm.kt b/sample/shared/src/jvmMain/kotlin/com/attafitamim/kabin/Platform.jvm.kt deleted file mode 100644 index 293e419..0000000 --- a/sample/shared/src/jvmMain/kotlin/com/attafitamim/kabin/Platform.jvm.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.attafitamim.kabin - -class JVMPlatform: Platform { - override val name: String = "JVM" -} - -actual fun getPlatform(): Platform = JVMPlatform() diff --git a/sample/shared/src/wasmJsMain/kotlin/com/attafitamim/kabin/Platform.wasmJs.kt b/sample/shared/src/wasmJsMain/kotlin/com/attafitamim/kabin/Platform.wasmJs.kt deleted file mode 100644 index 4feb065..0000000 --- a/sample/shared/src/wasmJsMain/kotlin/com/attafitamim/kabin/Platform.wasmJs.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.attafitamim.kabin - -class WasmJSPlatform: Platform { - override val name: String = "WasmJS" -} - -actual fun getPlatform(): Platform = - WasmJSPlatform()