Skip to content

Commit

Permalink
Fix whereTime method for PostgresGrammar with correct casting. (#23323)
Browse files Browse the repository at this point in the history
  • Loading branch information
pinguinjkeke authored and taylorotwell committed Feb 27, 2018
1 parent d9bf9d0 commit 65b6ad5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ protected function whereDate(Builder $query, $where)
return $this->wrap($where['column']).'::date '.$where['operator'].' '.$value;
}

/**
* Compile a "where time" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereTime(Builder $query, $where)
{
$value = $this->parameter($where['value']);

return $this->wrap($where['column']).'::time '.$where['operator'].' '.$value;
}

/**
* Compile a date based where clause.
*
Expand Down
10 changes: 9 additions & 1 deletion tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,19 @@ public function testWhereTimeOperatorOptionalMySql()
$this->assertEquals([0 => '22:00'], $builder->getBindings());
}

public function testWhereTimePostgres()
{
$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->whereTime('created_at', '>=', '22:00');
$this->assertEquals('select * from "users" where "created_at"::time >= ?', $builder->toSql());
$this->assertEquals([0 => '22:00'], $builder->getBindings());
}

public function testWhereTimeOperatorOptionalPostgres()
{
$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->whereTime('created_at', '22:00');
$this->assertEquals('select * from "users" where extract(time from "created_at") = ?', $builder->toSql());
$this->assertEquals('select * from "users" where "created_at"::time = ?', $builder->toSql());
$this->assertEquals([0 => '22:00'], $builder->getBindings());
}

Expand Down

0 comments on commit 65b6ad5

Please sign in to comment.