Skip to content

Commit

Permalink
Use the correct date formatting in get_stats depending on DB engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jelveh committed Dec 31, 2024
1 parent 13e5f7f commit 5d8ccf8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/backend/src/modules/apps/AppInformationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,12 @@ class AppInformationService extends BaseService {

const [openResult, userResult] = await Promise.all([
db.read(`
SELECT
DATE_FORMAT(FROM_UNIXTIME(ts/1000), '${timeFormat}') as period,
SELECT ` +
db.case({
mysql: `DATE_FORMAT(FROM_UNIXTIME(ts/1000), '${timeFormat}') as period, `,
sqlite: `STRFTIME('%Y-%m-%d %H', datetime(ts/1000, 'unixepoch'), '${timeFormat}') as period, `,
}) +
`
COUNT(_id) as count
FROM app_opens
WHERE app_uid = ?
Expand All @@ -384,8 +388,12 @@ class AppInformationService extends BaseService {
ORDER BY period
`, queryParams),
db.read(`
SELECT
DATE_FORMAT(FROM_UNIXTIME(ts/1000), '${timeFormat}') as period,
SELECT ` +
db.case({
mysql: `DATE_FORMAT(FROM_UNIXTIME(ts/1000), '${timeFormat}') as period, `,
sqlite: `STRFTIME('%Y-%m-%d %H', datetime(ts/1000, 'unixepoch'), '${timeFormat}') as period, `,
}) +
`
COUNT(DISTINCT user_id) as count
FROM app_opens
WHERE app_uid = ?
Expand Down

0 comments on commit 5d8ccf8

Please sign in to comment.