-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Migrate to dedicated station count endpoints (#93)
* Migrate to dedicated station count endpoints * Improved local helper function SQL security * Renamed request helper methods
- Loading branch information
1 parent
42098af
commit 5e1b373
Showing
5 changed files
with
152 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
import { getDailyDistinctCount, getMonthlyDistinctCount } from './request-helpers.js' | ||
|
||
/** | ||
* @param {import('pg').Pool} pgPool | ||
* @param {import('./typings').Filter} filter | ||
*/ | ||
export const fetchDailyStationMetrics = async (pgPool, filter) => { | ||
const { rows } = await pgPool.query(` | ||
SELECT day::TEXT, station_id | ||
FROM daily_stations | ||
WHERE day >= $1 AND day <= $2 | ||
GROUP BY day, station_id | ||
`, [ | ||
filter.from, | ||
filter.to | ||
]) | ||
return rows | ||
export const fetchDailyStationCount = async (pgPool, filter) => { | ||
return await getDailyDistinctCount({ | ||
pgPool, | ||
table: 'daily_stations', | ||
column: 'station_id', | ||
filter | ||
}) | ||
} | ||
|
||
/** | ||
* @param {import('pg').Pool} pgPool | ||
* @param {import('./typings').Filter} filter | ||
*/ | ||
export const fetchMonthlyStationCount = async (pgPool, filter) => { | ||
return await getMonthlyDistinctCount({ | ||
pgPool, | ||
table: 'daily_stations', | ||
column: 'station_id', | ||
filter | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters