// callback function - if error return it to callback. If no error then return rows (empty set)staticinsert(city,callback){db.query('INSERT INTO cities (city_name) VALUES ($1)',[city],(err,res)=>{if(err.error)returncallback(err);callback(res);});}
๐ป Code Examples - Frontend
method to add a city
// fetch an object that has a city property// after getting city list clear input fieldhandleAddCity=()=>{fetch('/api/cities',{method: 'post',headers: {'Content-Type': 'application/json'},body: JSON.stringify({city: this.state.newCityName})}).then(res=>res.json()).then(res=>{this.getCityList();this.setState({newCityName: ''});});};
๐ Features - Backend
All data stored in PostgreSQL database that can also be viewed and changed from the PostgreSQL shell (psql)
๐ Features - Frontend
React app created from the command prompt using Create React App
Status: Working front and back ends. App works and stores city names in PostgreSQL database. Deploy to Heroku not working - could be npm dependency issues or missing API access credentials in Heroku.
To-Do: Change backend so it checks if city already in database before adding it. Add commenting. Add functionality
Solve deploy issues: retry video 4 from 9.10 to create the correctly named database