Skip to content

Commit

Permalink
DOPE-260: add support for ordering by multiple OrderExpressions
Browse files Browse the repository at this point in the history
  • Loading branch information
jansigi committed Nov 22, 2024
1 parent 991edff commit 7edb811
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ interface ISelectOrderByClause<T : ValidType> : ISelectLimitClause<T> {
}

interface ISelectGroupByClause<T : ValidType> : ISelectOrderByClause<T> {
fun orderBy(orderExpression: OrderExpression) = SelectOrderByClause(orderExpression, parentClause = this)
fun orderBy(orderExpression: OrderExpression, vararg additionalOrderExpressions: OrderExpression) =
SelectOrderByClause(orderExpression, *additionalOrderExpressions, parentClause = this)
fun orderBy(expression: TypeExpression<out ValidType>, orderByType: OrderByType? = null) = orderBy(OrderExpression(expression, orderByType))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ class OrderByClauseTest : ManagerDependentTest {
assertEquals(expected.toDopeQuery(manager), actual.toDopeQuery(manager))
}

@Test
fun `should support order by function with multiple orderExpressions`() {
val parentClause = someSelectClause()
val orderExpression1 = OrderExpression(someStringField())
val orderExpression2 = OrderExpression(someNumberField(), ASC)
val expected = SelectOrderByClause(orderExpression1, orderExpression2, parentClause = parentClause)

val actual = parentClause.orderBy(orderExpression1, orderExpression2)

assertEquals(expected.toDopeQuery(manager), actual.toDopeQuery(manager))
}

@Test
fun `should support order by function with then order by with orderExpression`() {
val stringField = someStringField()
Expand Down

0 comments on commit 7edb811

Please sign in to comment.