Add createSport function
This commit is contained in:
		
							parent
							
								
									6f4a41fbd7
								
							
						
					
					
						commit
						64f4f9fb32
					
				
					 1 changed files with 26 additions and 0 deletions
				
			
		
							
								
								
									
										26
									
								
								database/scores/sports.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								database/scores/sports.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| const database = require('./database'); | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| class Sport { | ||||
|     constructor(id) { | ||||
|         this.id = id; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| async function createSport(name) { | ||||
|     query = `INSERT INTO scores.sports(sport_name)
 | ||||
|             VALUES($1);`;
 | ||||
|     await database.executeQuery(query, [name]); | ||||
| 
 | ||||
|     query = `SELECT sport_id FROM scores.sports
 | ||||
|             WHERE sport_name = $1` | ||||
|     const sportId = await database.executeQuery(query, [name]); | ||||
|     console.log(sportId); | ||||
| 
 | ||||
|     return new Sport(sportId[0][0]); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| exports.createSport = createSport; | ||||
		Reference in a new issue