Skip to content
Permalink
Browse files

Allow order by with expressions

Refs #79
  • Loading branch information...
SamelVhatargh authored and shadowhand committed Feb 4, 2019
1 parent 7ef84c1 commit fcafb397b30087bb818240477c8e1856079ea582
Showing with 14 additions and 1 deletion.
  1. +1 −1 src/functions.php
  2. +13 −0 tests/Query/SelectTest.php
@@ -28,7 +28,7 @@ function on(string $left, string $right): CriteriaInterface
return criteria('%s = %s', identify($left), identify($right));
}
function order(string $column, string $direction = null): StatementInterface
function order($column, string $direction = null): StatementInterface
{
if (empty($direction)) {
return identify($column);
@@ -5,8 +5,10 @@
use Latitude\QueryBuilder\TestCase;
use function Latitude\QueryBuilder\alias;
use function Latitude\QueryBuilder\express;
use function Latitude\QueryBuilder\field;
use function Latitude\QueryBuilder\fn;
use function Latitude\QueryBuilder\identify;
use function Latitude\QueryBuilder\on;
class SelectTest extends TestCase
@@ -254,6 +256,17 @@ public function testOrderByReset()
$this->assertParams([], $select);
}
public function testOrderByExpression()
{
$select = $this->factory
->select()
->from('users')
->orderBy(express("FIELD(%s, 'off')", identify('status')), 'DESC');
$this->assertSql("SELECT * FROM users ORDER BY FIELD(status, 'off') DESC", $select);
$this->assertParams([], $select);
}
public function testOffsetLimit()
{
$select = $this->factory

0 comments on commit fcafb39

Please sign in to comment.
You can’t perform that action at this time.