Add function to retrieve teams by sport

main
sudoer777 2021-11-20 21:43:19 -07:00
parent 16c90cf883
commit e37b10596e
1 changed files with 14 additions and 0 deletions

View File

@ -35,4 +35,18 @@ async function remove(id) {
RETURNING team_name;`; RETURNING team_name;`;
name = (await database.executeQuery(query, [id]))[0][0]; name = (await database.executeQuery(query, [id]))[0][0];
return new Team(id, name); return new Team(id, name);
}
async function retrieveBySport(sportID) {
query = `SELECT *
FROM scores.teams
WHERE sport_id = $1
ORDER BY team_name;`;
const table = await database.executeQuery(query);
const teamsList = [];
table.forEach((row) => {
teamsList.push(new Team(row[0], row[1]));
});
return teamsList;
} }