diff --git a/docs/drivers.md b/docs/drivers.md index 86003ab..2bcc173 100644 --- a/docs/drivers.md +++ b/docs/drivers.md @@ -8,3 +8,4 @@ We currently support two drivers: - MySQL - Sqlite +- PostgreSQL diff --git a/src/Adapters/PgsqlAdapter.php b/src/Adapters/PgsqlAdapter.php new file mode 100644 index 0000000..47e44b1 --- /dev/null +++ b/src/Adapters/PgsqlAdapter.php @@ -0,0 +1,22 @@ + '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}')"; + } +} diff --git a/src/Trend.php b/src/Trend.php index ecfe5b0..5a2c37b 100755 --- a/src/Trend.php +++ b/src/Trend.php @@ -5,6 +5,7 @@ use Carbon\CarbonPeriod; use Error; use Flowframe\Trend\Adapters\MySqlAdapter; +use Flowframe\Trend\Adapters\PgsqlAdapter; use Flowframe\Trend\Adapters\SqliteAdapter; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Carbon; @@ -157,6 +158,7 @@ protected function getSqlDate(): string $adapter = match ($this->builder->getConnection()->getDriverName()) { 'mysql' => new MySqlAdapter(), 'sqlite' => new SqliteAdapter(), + 'pgsql' => new PgsqlAdapter(), default => throw new Error('Unsupported database driver.'), };