visits added to site page

This commit is contained in:
2020-01-07 17:41:30 -05:00
parent e69a1e03f8
commit 571a65986c
6 changed files with 30 additions and 12 deletions

View File

@ -21,7 +21,7 @@ con.connect(function(err) {
});
con.query("CREATE TABLE sites(\
id int NOT NULL AUTO_INCREMENT,\
id int NOT NULL UNIQUE,\
category varchar(255),\
in_danger bool,\
date_inscribed int,\

View File

@ -10,6 +10,9 @@ var arr = [];
val.query.row.forEach(function(site){
var s = [];
// Changed ID to the UNESCO unique number.
// This is done in order to associate a visit to a site.
s.push(site.unique_number);
s.push(site.category);
s.push(site.danger != '' || false);
s.push(site.date_inscribed);
@ -38,7 +41,7 @@ con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
sql = "INSERT INTO sites (category, in_danger, date_inscribed, unesco_url, latitude, longitude, description, site, unesco_unique, img_url, states, slug) VALUES ?";
sql = "INSERT INTO sites (id, category, in_danger, date_inscribed, unesco_url, latitude, longitude, description, site, unesco_unique, img_url, states, slug) VALUES ?";
con.query(sql, [arr], function(err, res){
if (err) throw err;

View File

@ -2,14 +2,14 @@ var con = require('./db');
sql = "INSERT INTO visits (date, img, site_id) VALUES ?";
val = [
['10-15-2019','https://seanland.ca', '1'],
['10-17-2019','https://seanland.ca', '1'],
['01-17-2020','https://seanland.ca', '134'],
['11-23-2019','https://seanland.ca', '15']
['10-15-2019','https://seanland.ca', '203'],
['10-17-2019','https://seanland.ca', '169'],
['01-17-2020','https://seanland.ca', '520'],
['11-23-2019','https://seanland.ca', '520']
];
con.query(sql, [val], function(err, res){
if (err) throw err;
console.log("visits" + ": records inserted: " + res.affectedRows);
console.log("visit records inserted: " + res.affectedRows);
process.exit();
});