Skip to content

Commit 6694eba

Browse files
committed
Add comment about Kotlin context parameters
1 parent ff530c6 commit 6694eba

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Diff for: src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ open class GroupingCriteriaCollector : SubCriteriaCollector() {
235235
.build()
236236
}
237237

238-
// infix functions...we may be able to rewrite these as extension functions once Kotlin solves the multiple
239-
// receivers problem (https://youtrack.jetbrains.com/issue/KT-42435)
238+
// infix functions...we may be able to rewrite these as extension functions once Kotlin implements the context
239+
// parameters proposal (https://github.com/Kotlin/KEEP/issues/367)
240240

241241
// conditions for all data types
242242
fun BindableColumn<*>.isNull() = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNull())

Diff for: src/test/kotlin/examples/kotlin/mybatis3/mariadb/KMariaDBTest.kt

+14-8
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,15 @@ class KMariaDBTest {
143143
}
144144
}
145145

146-
// Note that the following example uses of KIsLikeEscape are a bit awkward and don't look as natural as the
147-
// built-in conditions. We should be able to improve this once Kotlin implements the context parameters
148-
// proposal (https://github.com/Kotlin/KEEP/issues/367)
146+
147+
/**
148+
* Shortcut function for KIsLikeEscape
149+
*
150+
* Note that the following example uses of this function are a bit awkward and don't look as natural as the
151+
* built-in conditions. We should be able to improve this once Kotlin implements the context parameters
152+
* proposal (https://github.com/Kotlin/KEEP/issues/367)
153+
*/
154+
fun <T : Any> isLike(value: T, escapeCharacter: Char? = null) = KIsLikeEscape.isLike(value, escapeCharacter)
149155

150156
@Test
151157
fun testIsLikeEscape() {
@@ -154,7 +160,7 @@ class KMariaDBTest {
154160
val selectStatement = select(id, description) {
155161
from(items)
156162
where {
157-
description(KIsLikeEscape.isLike("Item 1%", '#'))
163+
description(isLike("Item 1%", '#'))
158164
}
159165
}
160166

@@ -171,7 +177,7 @@ class KMariaDBTest {
171177
val selectStatement = select(id, description) {
172178
from(items)
173179
where {
174-
description(KIsLikeEscape.isLike("%fred%"))
180+
description(isLike("%fred%"))
175181
}
176182
}
177183

@@ -184,7 +190,7 @@ class KMariaDBTest {
184190
val selectStatement = select(id, description) {
185191
from(items)
186192
where {
187-
description(KIsLikeEscape.isLike("%fred%", '#').map { s -> s.uppercase(Locale.getDefault()) })
193+
description(isLike("%fred%", '#').map { s -> s.uppercase(Locale.getDefault()) })
188194
}
189195
}
190196

@@ -197,7 +203,7 @@ class KMariaDBTest {
197203
val selectStatement = select(id, description) {
198204
from(items)
199205
where {
200-
description(KIsLikeEscape.isLike("%fred%", '#').filter { _ -> false })
206+
description(isLike("%fred%", '#').filter { _ -> false })
201207
}
202208
configureStatement { isNonRenderingWhereClauseAllowed = true }
203209
}
@@ -211,7 +217,7 @@ class KMariaDBTest {
211217
val selectStatement = select(id, description) {
212218
from(items)
213219
where {
214-
description(KIsLikeEscape.isLike("%fred%", '#')
220+
description(isLike("%fred%", '#')
215221
.filter { _ -> true }
216222
.map { s -> s.uppercase(Locale.getDefault()) }
217223
.filter{_ -> false })

0 commit comments

Comments
 (0)