Skip to content

Commit

Permalink
Fix #12
Browse files Browse the repository at this point in the history
Fix PostgreSQL and SQLite support
  • Loading branch information
eliseekn committed Apr 7, 2024
1 parent c1a8129 commit 4d8ca38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/DatesFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function formatPeriod(string $period): string

if ($driver === 'mysql') {
return match ($period) {
Period::TODAY->value, Period::DAY->value => "weekday($this->dateColumn)",
Period::TODAY->value, Period::DAY->value => "day($this->dateColumn)",
Period::WEEK->value => "week($this->dateColumn)",
Period::MONTH->value => "month($this->dateColumn)",
default => "year($this->dateColumn)",
Expand All @@ -69,15 +69,15 @@ protected function formatPeriod(string $period): string

if ($driver === 'pgsql') {
return match ($period) {
Period::TODAY->value, Period::DAY->value => "EXTRACT(DOW FROM $this->dateColumn)",
Period::TODAY->value, Period::DAY->value => "EXTRACT(DAY FROM $this->dateColumn)",
Period::WEEK->value => "EXTRACT(WEEK FROM $this->dateColumn)",
Period::MONTH->value => "EXTRACT(MONTH FROM $this->dateColumn)",
default => "EXTRACT(YEAR FROM $this->dateColumn)",
};
}

return match ($period) {
Period::TODAY->value, Period::DAY->value => "strftime('%w', $this->dateColumn)",
Period::TODAY->value, Period::DAY->value => "strftime('%d', $this->dateColumn)",
Period::WEEK->value => "strftime('%W', $this->dateColumn)",
Period::MONTH->value => "strftime('%m', $this->dateColumn)",
default => "strftime('%Y', $this->dateColumn)",
Expand Down
4 changes: 3 additions & 1 deletion src/LaravelMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ protected function withVariations(int $count = 1): int
throw new InvalidPeriodException();
}

$laravelMetrics = (new self($this->builder));
$laravelMetrics = (new self(DB::table($this->table)))
->by($this->period, $count)
->aggregate($this->aggregate, str_replace($this->table . '.', '', $this->column));

$result = match ($this->period) {
Period::DAY->value => $laravelMetrics
Expand Down

0 comments on commit 4d8ca38

Please sign in to comment.