mirror of
https://github.com/flarum/core.git
synced 2025-08-12 03:14:33 +02:00
feat: add support for PgSQL (#3985)
* feat: add support for `PgSQL` * chore: generate dump * feat: query exception errors db driver hint * feat: allow defining supported databases * chore: review comments * feat: setting for pgsql preferred search config
This commit is contained in:
@@ -11,6 +11,7 @@ namespace Flarum\Statistics\Api\Controller;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Http\Exception\InvalidParameterException;
|
||||
use Flarum\Http\RequestUtil;
|
||||
@@ -130,11 +131,19 @@ class ShowStatisticsData implements RequestHandlerInterface
|
||||
$endDate = new DateTime();
|
||||
}
|
||||
|
||||
$formats = match ($query->getConnection()->getDriverName()) {
|
||||
'pgsql' => ['YYYY-MM-DD HH24:00:00', 'YYYY-MM-DD'],
|
||||
default => ['%Y-%m-%d %H:00:00', '%Y-%m-%d'],
|
||||
};
|
||||
|
||||
// if within the last 24 hours, group by hour
|
||||
$format = 'CASE WHEN '.$column.' > ? THEN \'%Y-%m-%d %H:00:00\' ELSE \'%Y-%m-%d\' END';
|
||||
$format = "CASE WHEN $column > ? THEN '$formats[0]' ELSE '$formats[1]' END";
|
||||
|
||||
$dbFormattedDatetime = match ($query->getConnection()->getDriverName()) {
|
||||
'sqlite' => 'strftime('.$format.', '.$column.')',
|
||||
default => 'DATE_FORMAT('.$column.', '.$format.')',
|
||||
'sqlite' => "strftime($format, $column)",
|
||||
'pgsql' => "TO_CHAR($column, $format)",
|
||||
'mysql' => "DATE_FORMAT($column, $format)",
|
||||
default => throw new Exception('Unsupported database driver'),
|
||||
};
|
||||
|
||||
$results = $query
|
||||
|
Reference in New Issue
Block a user