Massive/set.service.ts

20 lines
654 B
TypeScript
Raw Normal View History

2022-10-05 10:38:52 +00:00
import CountMany from './count-many';
import {db} from './db';
export const countMany = async (names: string[]): Promise<CountMany[]> => {
2022-10-30 01:46:32 +00:00
const questions = names.map(_ => '(?)').join(',');
console.log({questions, names});
2022-10-05 10:38:52 +00:00
const select = `
SELECT workouts.name, COUNT(sets.id) as total
2022-10-30 01:46:32 +00:00
FROM (select 0 as name union values ${questions}) as workouts
LEFT JOIN sets ON sets.name = workouts.name
AND sets.created LIKE STRFTIME('%Y-%m-%d%%', 'now', 'localtime')
AND NOT sets.hidden
2022-10-30 01:46:32 +00:00
GROUP BY workouts.name
LIMIT -1
OFFSET 1
2022-10-05 10:38:52 +00:00
`;
const [result] = await db.executeSql(select, names);
2022-10-05 10:38:52 +00:00
return result.rows.raw();
};