remove dropoff calc from db query

This commit is contained in:
Francis Cao 2023-07-24 11:57:46 -07:00
parent 858f465566
commit 711ad2bbcf
3 changed files with 15 additions and 34 deletions

View file

@ -44,18 +44,6 @@ function getAddMinutesQuery(field: string, minutes: number) {
}
}
function getDropoffQuery() {
const db = getDatabaseType(process.env.DATABASE_URL);
if (db === POSTGRESQL) {
return `round((1.0 - count::numeric/lag(nullif(count, 0), 1) over ()),2) * 100`;
}
if (db === MYSQL) {
return `round((1.0 - count/LAG(nullif(count, 0), 1) OVER (ORDER BY level)),2) * 100`;
}
}
function getDateQuery(field: string, unit: string, timezone?: string): string {
const db = getDatabaseType(process.env.DATABASE_URL);
@ -217,15 +205,12 @@ async function rawQuery(query: string, params: never[] = []): Promise<any> {
const sql = db === MYSQL ? query.replace(/\$[0-9]+/g, '?') : query;
// console.log(sql);
// console.log(params);
return prisma.rawQuery(sql, params);
}
export default {
...prisma,
getAddMinutesQuery,
getDropoffQuery,
getDateQuery,
getTimestampInterval,
getFilterQuery,