diff --git a/gradle.properties b/gradle.properties index 337c3b3..1d9f28f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.daemon=true org.gradle.parallel=true # Maven GROUP=com.mercury.sqkon -VERSION_NAME=1.0.0-alpha06 +VERSION_NAME=1.0.0-alpha07 POM_NAME=Sqkon POM_INCEPTION_YEAR=2024 POM_URL=https://github.com/MercuryTechnologies/sqkon/ diff --git a/library/src/commonMain/kotlin/com/mercury/sqkon/db/JsonPath.kt b/library/src/commonMain/kotlin/com/mercury/sqkon/db/JsonPath.kt index 29d4855..e2ba13d 100644 --- a/library/src/commonMain/kotlin/com/mercury/sqkon/db/JsonPath.kt +++ b/library/src/commonMain/kotlin/com/mercury/sqkon/db/JsonPath.kt @@ -80,7 +80,8 @@ class JsonPathBuilder // Handles collection property type and extracts the element type vs the list type @PublishedApi - internal inline fun withList( + @JvmName("withList") + internal inline fun with( property: KProperty1>, serialName: String? = null, block: JsonPathNode.() -> Unit = {} @@ -135,20 +136,20 @@ class JsonPathBuilder // Builder Methods to start building paths -inline fun KProperty1.builder( +inline fun KProperty1.builder( serialName: String? = null, block: JsonPathNode.() -> Unit = {} ): JsonPathBuilder { return JsonPathBuilder().with(property = this, serialName = serialName, block = block) } -inline fun KProperty1>.builderFromList( +inline fun KProperty1>.builderFromList( block: JsonPathNode.() -> Unit = {} ): JsonPathBuilder { - return JsonPathBuilder().withList(property = this, block = block) + return JsonPathBuilder().with(property = this, block = block) } -inline fun KProperty1.then( +inline fun KProperty1.then( property: KProperty1, fromSerialName: String? = null, thenSerialName: String? = null, @@ -160,50 +161,55 @@ inline fun KProperty1>.thenFromList( +@JvmName("thenFromList") +inline fun KProperty1>.then( property: KProperty1, fromSerialName: String? = null, thenSerialName: String? = null, block: JsonPathNode.() -> Unit = {} ): JsonPathBuilder { return JsonPathBuilder() - .withList(property = this, fromSerialName) { + .with(property = this, fromSerialName) { then(property = property, serialName = thenSerialName, block = block) } } -inline fun KProperty1.thenList( +@JvmName("thenList") +inline fun KProperty1.then( property: KProperty1>, block: JsonPathNode.() -> Unit = {} ): JsonPathBuilder { return JsonPathBuilder().with(property = this) { - thenList(property = property, block = block) + then(property = property, block = block) } } inline fun KClass.with( property: KProperty1, + serialName: String? = null, block: JsonPathNode.() -> Unit = {} ): JsonPathBuilder { return JsonPathBuilder().with( - baseType = typeOf(), property = property, block = block - ) + baseType = typeOf(), property = property, block = block, serialName = serialName, + ) } // Handles collection property type @Suppress("UnusedReceiverParameter") inline fun KClass.withList( property: KProperty1>, + serialName: String? = null, block: JsonPathNode.() -> Unit = {} ): JsonPathBuilder { - return JsonPathBuilder().withList(property = property, block = block) + return JsonPathBuilder() + .with(property = property, block = block, serialName = serialName) } /** * Represents a path in a JSON object, using limited reflection and descriptors to build the path. * - * Start building using [with] or [withList] + * Start building using [with]. */ class JsonPathNode @PublishedApi @@ -241,7 +247,8 @@ internal constructor( * * This returns the Collection element type, so you can chain into the next property. */ - inline fun thenList( + @JvmName("thenList") + inline fun then( property: KProperty1>, serialName: String? = null, block: JsonPathNode.() -> Unit = {} diff --git a/library/src/commonTest/kotlin/com/mercury/sqkon/TestDataClasses.kt b/library/src/commonTest/kotlin/com/mercury/sqkon/TestDataClasses.kt index 9f7875d..99a3ad8 100644 --- a/library/src/commonTest/kotlin/com/mercury/sqkon/TestDataClasses.kt +++ b/library/src/commonTest/kotlin/com/mercury/sqkon/TestDataClasses.kt @@ -30,6 +30,7 @@ data class TestObject( data class TestObjectChild( val createdAt: Instant = Clock.System.now(), val updatedAt: Instant = Clock.System.now(), + val subList: List = listOf("1", "2", "3"), ) @Serializable diff --git a/library/src/commonTest/kotlin/com/mercury/sqkon/db/JsonPathBuilderTest.kt b/library/src/commonTest/kotlin/com/mercury/sqkon/db/JsonPathBuilderTest.kt index 9ba4257..2e8f3d0 100644 --- a/library/src/commonTest/kotlin/com/mercury/sqkon/db/JsonPathBuilderTest.kt +++ b/library/src/commonTest/kotlin/com/mercury/sqkon/db/JsonPathBuilderTest.kt @@ -103,9 +103,16 @@ class JsonPathBuilderTest { assertEquals(expected = "\$.list[%].createdAt", actual = builder.buildPath()) } + @Test + fun build_with_then_list() { + val builder = TestObject::child.then(TestObjectChild::subList) + assertEquals(expected = "\$.child.subList[%]", actual = builder.buildPath()) + } + + @Test fun build_with_list_then() { - val builder = TestObject::list.thenFromList(TestObjectChild::createdAt) + val builder = TestObject::list.then(TestObjectChild::createdAt) assertEquals(expected = "\$.list[%].createdAt", actual = builder.buildPath()) } diff --git a/library/src/commonTest/kotlin/com/mercury/sqkon/db/KeyValueStorageTest.kt b/library/src/commonTest/kotlin/com/mercury/sqkon/db/KeyValueStorageTest.kt index 91a4021..d939c35 100644 --- a/library/src/commonTest/kotlin/com/mercury/sqkon/db/KeyValueStorageTest.kt +++ b/library/src/commonTest/kotlin/com/mercury/sqkon/db/KeyValueStorageTest.kt @@ -516,5 +516,20 @@ class KeyValueStorageTest { } } + @Test + fun select_inList() = runTest{ + val expectedO = TestObject() + testObjectStorage.insert(expectedO.id, expectedO) + + val expectedList = expectedO.list.map { it.createdAt.toString() } + + val actual = testObjectStorage.select( + where = TestObject::list.then(TestObjectChild::createdAt) inList expectedList + ).first() + + assertEquals(expectedO, actual.first()) + assertEquals(expectedO.list, actual.first().list) + } + }