From 2d14395b61c930862c072dd66561796027fe8383 Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Sat, 20 Nov 2021 18:07:37 -0700 Subject: [PATCH] Add function to retrieve all sports from database --- database/scores/sports.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/database/scores/sports.js b/database/scores/sports.js index bd719fc..38f35cf 100644 --- a/database/scores/sports.js +++ b/database/scores/sports.js @@ -35,10 +35,24 @@ async function remove(id) { return new Sport(id, name); } +async function retrieveAll() { + query = `SELECT * + FROM scores.sports + ORDER BY sport_name;`; + const table = await database.executeQuery(query); + + const sportsList = []; + table.forEach((row) => { + sportsList.push(new Sport(row[0], row[1])); + }); + return sportsList; +} + exports.create = create; exports.rename = rename; -exports.remove = remove; \ No newline at end of file +exports.remove = remove; +exports.retrieveAll = retrieveAll; \ No newline at end of file