Skip to content

Commit

Permalink
Merge pull request #37 from abishekrsrikaanth/sqlite-support
Browse files Browse the repository at this point in the history
Completing SQLite Support
  • Loading branch information
freekmurze authored Feb 29, 2024
2 parents b1849d3 + a99b7cb commit 7930ce1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/StatsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,21 @@ public static function getPeriodDateFormat(string $period): string
};
}

if ($dbDriver === 'sqlite') {
return match ($period) {
'year' => "strftime('%Y', created_at)",
'month' => "strftime('%Y-%m', created_at)",
'week' => "strftime('%Y%W', created_at)",
'day' => "strftime('%Y-%m-%d', created_at)",
'hour' => "strftime('%Y-%m-%d %H', created_at)",
'minute' => "strftime('%Y-%m-%d %H:%M', created_at)",
};
}

return match ($period) {
'year' => "date_format(created_at,'%Y')",
'month' => "date_format(created_at,'%Y-%m')",
'week' => $dbDriver === 'mysql' ? "yearweek(created_at, 3)" : "strftime('%Y%W')", // see https://stackoverflow.com/questions/15562270/php-datew-vs-mysql-yearweeknow
'week' => "yearweek(created_at, 3)",
'day' => "date_format(created_at,'%Y-%m-%d')",
'hour' => "date_format(created_at,'%Y-%m-%d %H')",
'minute' => "date_format(created_at,'%Y-%m-%d %H:%i')",
Expand Down

0 comments on commit 7930ce1

Please sign in to comment.