-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting date format for Postgres in an adapter
- Loading branch information
1 parent
6fda6e4
commit ba62e0c
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Flowframe\Trend\Adapters; | ||
|
||
use Error; | ||
|
||
class PgsqlAdapter extends AbstractAdapter | ||
{ | ||
public function format(string $column, string $interval): string | ||
{ | ||
$format = match ($interval) { | ||
'minute' => 'YYYY-MM-DD HH24:MI:00', | ||
'hour' => 'YYYY-MM-DD HH24:00:00', | ||
'day' => 'YYYY-MM-DD', | ||
'month' => 'YYYY-MM', | ||
'year' => 'YYYY', | ||
default => throw new Error('Invalid interval.'), | ||
}; | ||
|
||
return "to_char({$column}, '{$format}')"; | ||
} | ||
} |