Skip to content
This repository has been archived by the owner on Mar 22, 2020. It is now read-only.

Commit

Permalink
Merge 7e73aff into f3531df
Browse files Browse the repository at this point in the history
  • Loading branch information
nrocco committed Oct 29, 2015
2 parents f3531df + 7e73aff commit cf43242
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/RestApi/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RestApi
'contains' => 'LIKE',
'icontains' => 'LIKE', //TODO: on postgres this is ilike

'day' => '=',
'month' => '=',
'year' => '=',
];
Expand Down Expand Up @@ -525,6 +526,13 @@ public function addWhere($key, $value)
return "date_part('month', {$column}) = {$this->database->quote($value)}";
}
throw new \RuntimeException("Unsupported platform {$platform}");
} elseif ('day' === $lookupType) {
if ('sqlite' === $platform) {
return "strftime('%d', {$column}) = {$this->database->quote($value)}";
} elseif ('postgresql' === $platform) {
return "date_part('day', {$column}) = {$this->database->quote($value)}";
}
throw new \RuntimeException("Unsupported platform {$platform}");
}

if ('postgresql' === $platform) {
Expand Down
7 changes: 6 additions & 1 deletion src/RestApi/Tests/RestApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ public function testReadCollectionFilter()
{
$api = $this->getApiWithDataLoaded();

$todos = $api->readCollection('todos', ['file__notnull' => 'yes', 'created__year' => 2014, 'updated__month' => 6]);
$todos = $api->readCollection('todos', [
'file__notnull' => 'yes',
'created__year' => 2014,
'updated__month' => 6,
'updated__day' => 1
]);
$this->assertEquals(200, $todos['code']);
$this->assertEquals(0, $todos['headers']['X-Pagination-Total']);
$this->assertEmpty($todos['body']);
Expand Down

0 comments on commit cf43242

Please sign in to comment.