2022-10-05 10:38:52 +00:00
|
|
|
import CountMany from './count-many';
|
2022-09-04 04:56:46 +00:00
|
|
|
import {db} from './db';
|
2022-09-25 05:05:15 +00:00
|
|
|
|
2022-10-30 01:27:22 +00:00
|
|
|
export const countMany = async (names: string[]): Promise<CountMany[]> => {
|
2022-10-30 01:46:32 +00:00
|
|
|
const questions = names.map(_ => '(?)').join(',');
|
2022-10-30 01:27:22 +00:00
|
|
|
console.log({questions, names});
|
2022-10-05 10:38:52 +00:00
|
|
|
const select = `
|
2022-10-30 01:27:22 +00:00
|
|
|
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
|
2022-10-30 01:27:22 +00:00
|
|
|
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
|
|
|
`;
|
2022-10-30 01:27:22 +00:00
|
|
|
const [result] = await db.executeSql(select, names);
|
2022-10-05 10:38:52 +00:00
|
|
|
return result.rows.raw();
|
|
|
|
};
|