sendou.ink/app/features/tournament-bracket/queries/bestOfsByTournamentId.server.ts
Kalle c0ec15b7de
Some checks failed
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
Unify db type files
2025-03-21 21:47:08 +02:00

23 lines
744 B
TypeScript

import { sql } from "~/db/sql";
import type { Tables } from "~/db/tables";
const stm = sql.prepare(/* sql */ `
select
"TournamentRound"."id" as "roundId",
"TournamentMatch"."bestOf"
from "TournamentRound"
left join "TournamentMatch" on "TournamentRound"."id" = "TournamentMatch"."roundId"
left join "TournamentStage" on "TournamentRound"."stageId" = "TournamentStage"."id"
where "TournamentStage"."tournamentId" = @tournamentId
group by "TournamentRound"."id"
`);
interface BestOfByTournamentId {
roundId: Tables["TournamentRound"]["id"];
bestOf: Tables["TournamentMatch"]["bestOf"];
}
export function bestOfsByTournamentId(tournamentId: number) {
return stm.all({ tournamentId }) as BestOfByTournamentId[];
}