initial commit, database config working, pug template basic config, generated site working
This commit is contained in:
45
database/build.js
Normal file
45
database/build.js
Normal file
@ -0,0 +1,45 @@
|
||||
var con = require('./db');
|
||||
|
||||
con.connect(function(err) {
|
||||
if (err) throw err;
|
||||
console.log("Connected!");
|
||||
con.query("CREATE DATABASE unesco", function (err, res) {
|
||||
if (err) throw err;
|
||||
console.log('"unesco" Database created.');
|
||||
});
|
||||
|
||||
con.query("USE unesco", function (err, res) {
|
||||
if (err) throw err;
|
||||
console.log('"unesco" Database selected.');
|
||||
});
|
||||
|
||||
con.query("CREATE TABLE sites(\
|
||||
id int NOT NULL AUTO_INCREMENT,\
|
||||
category varchar(255),\
|
||||
in_danger bool,\
|
||||
date_inscribed int,\
|
||||
unesco_url varchar(255),\
|
||||
latitude varchar(255),\
|
||||
longitude varchar(255),\
|
||||
description varchar(5000),\
|
||||
site varchar(255),\
|
||||
unesco_unique int,\
|
||||
PRIMARY KEY (id)\
|
||||
)", function(err, res){
|
||||
if (err) throw err;
|
||||
console.log("sites Table Created.");
|
||||
});
|
||||
|
||||
con.query("CREATE TABLE visits(\
|
||||
id int NOT NULL AUTO_INCREMENT,\
|
||||
date varchar(255),\
|
||||
img varchar(255),\
|
||||
site_id int,\
|
||||
FOREIGN KEY (site_id) REFERENCES sites(id),\
|
||||
PRIMARY KEY (id)\
|
||||
)", function(err, res){
|
||||
if (err) throw err;
|
||||
console.log("visits Table Created.");
|
||||
process.exit();
|
||||
});
|
||||
});
|
11
database/db.js
Normal file
11
database/db.js
Normal file
@ -0,0 +1,11 @@
|
||||
var mysql = require('mysql');
|
||||
|
||||
// This information is only used for testing - change to production before deploying
|
||||
var con = mysql.createConnection({
|
||||
host: "localhost",
|
||||
user: "root",
|
||||
password: "root"
|
||||
// database: "unesco"
|
||||
});
|
||||
|
||||
module.exports = con;
|
11
database/drop-database.js
Normal file
11
database/drop-database.js
Normal file
@ -0,0 +1,11 @@
|
||||
var con = require('./db');
|
||||
|
||||
con.connect(function(err) {
|
||||
if (err) throw err;
|
||||
console.log("Connected!");
|
||||
con.query("DROP DATABASE unesco", function (err, result) {
|
||||
if (err) throw err;
|
||||
console.log('"unesco" Database dropped');
|
||||
process.exit();
|
||||
});
|
||||
});
|
35
database/fill-database.js
Normal file
35
database/fill-database.js
Normal file
@ -0,0 +1,35 @@
|
||||
var con = require('./db');
|
||||
|
||||
con.connect(function(err) {
|
||||
if (err) throw err;
|
||||
console.log("Connected!");
|
||||
|
||||
con.query("USE unesco", function (err, res) {
|
||||
if (err) throw err;
|
||||
console.log('"unesco" Database selected.');
|
||||
});
|
||||
|
||||
sql = "INSERT INTO sites (category, date_inscribed, unesco_url, latitude, longitude, description, site, unesco_unique) VALUES ?";
|
||||
val = [
|
||||
['Natural','2007','https://whc.unesco.org/en/list/1133','49.0097222222', '22.3388888889', '<p><span>This transboundary property stretches over 12 countries. Since the end of the last Ice Age, European Beech spread from a few isolated refuge areas in the Alps, Carpathians</span><span>, Dinarides</span><span>, Mediterranean and Pyrenees over a short period of a few thousand years in a process that is still ongoing. The successful expansion across a whole continent is related to the tree’s </span><span>adaptability and tolerance of different climatic, geographical and physical conditions. </span></p>', 'Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe', '2152'],
|
||||
['Cultural','2014','https://whc.unesco.org/en/list/1459','-18.2500000000', '-69.5916666667', '<p>This site is an extensive Inca communication, trade and defence network of roads covering 30,000 km. Constructed by the Incas over several centuries and partly based on pre-Inca infrastructure, this extraordinary network through one of the world’s most extreme geographical terrains linked the snow-capped peaks of the Andes – at an altitude of more than 6,000 m – to the coast, running through hot rainforests, fertile valleys and absolute deserts. It reached its maximum expansion in the 15th century, when it spread across the length a significance', 'Qhapaq Ñan, Andean Road System', '2003']
|
||||
];
|
||||
|
||||
con.query(sql, [val], function(err, res){
|
||||
if (err) throw err;
|
||||
console.log("sites" + ": records inserted: " + res.affectedRows);
|
||||
});
|
||||
|
||||
sql = "INSERT INTO visits (date, img, site_id) VALUES ?";
|
||||
val = [
|
||||
['10-15-2019','https://seanland.ca', '1'],
|
||||
['10-17-2019','https://seanland.ca', '1']
|
||||
];
|
||||
|
||||
con.query(sql, [val], function(err, res){
|
||||
if (err) throw err;
|
||||
console.log("visits" + ": records inserted: " + res.affectedRows);
|
||||
process.exit();
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user