File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed
main/kotlin/me/liuwj/ktorm/dsl
test/kotlin/me/liuwj/ktorm/dsl Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,7 @@ package me.liuwj.ktorm.dsl
33import me.liuwj.ktorm.database.Database
44import me.liuwj.ktorm.database.prepareStatement
55import me.liuwj.ktorm.expression.*
6- import me.liuwj.ktorm.schema.ColumnDeclaring
7- import me.liuwj.ktorm.schema.DoubleSqlType
8- import me.liuwj.ktorm.schema.IntSqlType
9- import me.liuwj.ktorm.schema.Table
6+ import me.liuwj.ktorm.schema.*
107import java.sql.ResultSet
118import javax.sql.rowset.RowSetProvider
129
@@ -192,6 +189,14 @@ inline fun Query.whereWithOrConditions(block: (MutableList<ScalarExpression<Bool
192189 }
193190}
194191
192+ fun Iterable<ScalarExpression<Boolean>>.combineConditions (): ScalarExpression <Boolean > {
193+ if (this .any()) {
194+ return this .reduce { a, b -> a and b }
195+ } else {
196+ return ArgumentExpression (true , BooleanSqlType )
197+ }
198+ }
199+
195200fun Query.groupBy (vararg columns : ColumnDeclaring <* >): Query {
196201 return this .withExpression { expr ->
197202 when (expr) {
Original file line number Diff line number Diff line change 11package me.liuwj.ktorm.dsl
22
33import me.liuwj.ktorm.BaseTest
4+ import me.liuwj.ktorm.expression.ScalarExpression
45import org.junit.Test
56
67/* *
@@ -57,6 +58,21 @@ class QueryTest : BaseTest() {
5758 assert (name == " vince" )
5859 }
5960
61+ @Test
62+ fun testCombineConditions () {
63+ val t = Employees .aliased(" t" )
64+
65+ val names = t
66+ .select(t.name)
67+ .where { emptyList<ScalarExpression <Boolean >>().combineConditions() }
68+ .orderBy(t.id.asc())
69+ .map { it.getString(1 ) }
70+
71+ assert (names.size == 4 )
72+ assert (names[0 ] == " vince" )
73+ assert (names[1 ] == " marry" )
74+ }
75+
6076 @Test
6177 fun testOrderBy () {
6278 val names = Employees
You can’t perform that action at this time.
0 commit comments