skysql_field
Rob Hedgpeth 2020-03-20 12:07:06 -05:00
rodzic 1aeb0cca53
commit eb0b741abb
12 zmienionych plików z 51 dodań i 61 usunięć

Wyświetl plik

@ -1,6 +1,8 @@
const fs = require("fs");
var mariadb = require('mariadb');
require('dotenv').config();
const serverCert = [fs.readFileSync("skysql_chain.pem", "utf8")]
const pool = mariadb.createPool({
host: process.env.DB_HOST,
@ -8,15 +10,12 @@ const pool = mariadb.createPool({
password: process.env.DB_PASS,
port: process.env.DB_PORT,
multipleStatements: true,
connectionLimit: 5
/*timezone: 'UTC',
dateStrings: [
'DATE',
'DATETIME'
]*/
connectionLimit: 5,
ssl: {
ca: serverCert
}
});
module.exports={
getConnection: function(){
return new Promise(function(resolve,reject){

Wyświetl plik

@ -9,7 +9,7 @@ router.get("/", async (req, res, next) => {
let conn;
try {
conn = await pool.getConnection();
var query = "select * from innodb_schmema.airlines order by airline";
var query = "select * from travel.airlines order by airline";
var rows = await conn.query(query);
res.send(rows);
throw err;

Wyświetl plik

@ -9,7 +9,7 @@ router.get("/", async (req, res, next) => {
let conn;
try {
conn = await pool.getConnection();
var query = "select iata_code, airport from innodb_schema.airports group by airport, iata_code order by airport";
var query = "select iata_code, airport from travel.airports group by airport, iata_code order by airport";
var rows = await conn.query(query);
res.send(rows);
} catch (err) {

Wyświetl plik

@ -30,13 +30,13 @@ router.get("/", async (req, res, next) => {
f.dep_time, \
f.arr_time, \
fh.avg_delay, \
(select avg(arr_time - dep_time) from columnstore_schema.flights \
where month = ? and day = ? and origin = ? and dest = ? and carrier = t.carrier and year >= 2014) avg_duration, \
(select avg(arr_time - dep_time) from travel_history.flights \
where month = ? and day = ? and origin = ? and dest = ? and carrier = t.carrier) avg_duration, \
fh.delayed_pct, \
fh.cancelled_pct \
from \
innodb_schema.tickets t, \
(select * from innodb_schema.flights where year = ? and month = ? and day = ?) f, \
travel.tickets t, \
(select * from travel.flights where year = ? and month = ? and day = ?) f, \
(select \
a.avg_delay, \
round(100 * (a.`delayed` / a.volume), 2) delayed_pct, \
@ -50,11 +50,10 @@ router.get("/", async (req, res, next) => {
avg(dep_delay) avg_delay, \
carrier \
from \
columnstore_schema.flights \
travel_history.flights \
where \
year >= 2014 and \
month = ? and day = ? and origin = ? and dest = ? group by carrier) a) fh, \
innodb_schema.airlines a \
travel.airlines a \
where \
t.carrier = f.carrier and \
t.fl_date = f.fl_date and \

Wyświetl plik

@ -21,10 +21,10 @@ router.get("/", async (req, res, next) => {
fh.delayed_pct, \
fh.avg_delay \
from \
innodb_schema.trips tr inner join \
innodb_schema.tickets t on tr.ticket_id = t.id inner join \
innodb_schema.airlines a on t.carrier = a.iata_code, \
(select * from innodb_schema.flights where year >= 2020) f, \
travel.trips tr inner join \
travel.tickets t on tr.ticket_id = t.id inner join \
travel.airlines a on t.carrier = a.iata_code, \
(select * from travel.flights where year >= 2020) f, \
(select \
a.avg_delay, \
round(100 * (a.`delayed` / a.volume), 2) delayed_pct, \
@ -42,11 +42,10 @@ router.get("/", async (req, res, next) => {
month, \
day \
from \
columnstore_schema.flights \
travel_history.flights \
where \
year >= 2014 and \
month in (select month(fl_date) from innodb_schema.trips tr inner join innodb_schema.tickets t on tr.ticket_id = t.id) and \
day in (select day(fl_date) from innodb_schema.trips tr inner join innodb_schema.tickets t on tr.ticket_id = t.id) \
month in (select month(fl_date) from travel.trips tr inner join travel.tickets t on tr.ticket_id = t.id) and \
day in (select day(fl_date) from travel.trips tr inner join travel.tickets t on tr.ticket_id = t.id) \
group by \
day, \
month, \
@ -122,7 +121,7 @@ function round(value, precision) {
// You can either tie into an existing Weather Forecast API
// or provide hard-coded lookups like the following.
var forecasts = {
"ORD_2020-02-27": {
"ORD_2020-03-27": {
description: "Snow",
icon: "snow",
temp_low: "-2°C",
@ -130,7 +129,7 @@ var forecasts = {
precip_probability: .6,
wind_speed: 15
},
"LAX_2020-02-28": {
"LAX_2020-03-28": {
description: "Clear",
icon: "clear-day",
temp_low: "13°C",

Wyświetl plik

@ -1,14 +1,19 @@
const fs = require("fs");
var mariadb = require('mariadb');
require('dotenv').config();
const serverCert = [fs.readFileSync("skysql_chain.pem", "utf8")];
const pool = mariadb.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
multipleStatements: true,
connectionLimit: 5
connectionLimit: 5,
ssl: {
ca: serverCert
}
});
module.exports={

Wyświetl plik

@ -9,7 +9,7 @@ router.get("/", async (req, res, next) => {
let conn;
try {
conn = await pool.getConnection();
var query = "select * from airlines order by airline";
var query = "select * from travel.airlines order by airline";
var rows = await conn.query(query);
res.send(rows);
} catch (err) {

Wyświetl plik

@ -9,7 +9,7 @@ router.get("/", async (req, res, next) => {
let conn;
try {
conn = await pool.getConnection();
var query = "select iata_code, airport from airports group by airport, iata_code order by airport";
var query = "select iata_code, airport from travel.airports group by airport, iata_code order by airport";
var rows = await conn.query(query);
res.send(rows);
} catch (err) {

Wyświetl plik

@ -29,7 +29,7 @@ router.get("/airlines_stats", async (req, res, next) => {
"select f.carrier, a.airline, count(*) volume, " +
"sum(case when dep_delay > 0 then 1 else 0 end) `delayed`, " +
"sum(diverted) diverted, sum(cancelled) cancelled " +
"from flights f join airlines a on f.carrier = a.iata_code " +
"from travel_history.flights f join travel.airlines a on f.carrier = a.iata_code " +
"where " +
"f.origin = ? and " +
"f.dest = ? and " +
@ -86,7 +86,7 @@ router.get("/airline_delays", async (req, res, next) => {
"avg(late_aircraft_delay) late_aircraft_delayed, " +
"avg(weather_delay) weather_delayed " +
"from " +
"flights f join airlines a on f.carrier = a.iata_code " +
"travel_history.flights f join travel.airlines a on f.carrier = a.iata_code " +
"where " +
"f.origin = ? and f.dest = ? and f.carrier = ? and f.year >= ? and f.year <= ?";
@ -129,7 +129,7 @@ router.get("/delays_comparison", async (req, res, next) => {
"avg(late_aircraft_delay) late_aircraft, " +
"avg(weather_delay) weather " +
"from " +
"flights f " +
"travel_history.flights f " +
"where " +
"f.origin = ? " +
"and f.dest = ? " +
@ -151,7 +151,7 @@ router.get("/delays_comparison", async (req, res, next) => {
"avg(late_aircraft_delay) late_aircraft, " +
"avg(weather_delay) weather " +
"from " +
"flights f " +
"travel_history.flights f " +
"where " +
"f.origin = ? " +
"and f.dest = ? " +

Wyświetl plik

@ -3,7 +3,7 @@ var mariadb = require('mariadb');
require('dotenv').config();
// For SSL connections
//const serverCert = [fs.readFileSync("skysql_chain.pem", "utf8")];
const serverCert = [fs.readFileSync("skysql_chain.pem", "utf8")];
var pools = [
mariadb.createPool({
@ -13,20 +13,11 @@ var pools = [
port: process.env.DB_PORT_1,
database: process.env.DB_NAME_1,
multipleStatements: true,
connectionLimit: 5
})/*,
mariadb.createPool({
host: '<host_address>',
user:'<user>',
password: '<password>',
database: 'orders',
port: 5002,
multipleStatements: true,
connectionLimit: 5,
ssl: {
ca: serverCert
}
})*/
})
];
module.exports={

Wyświetl plik

@ -1,14 +1,8 @@
const fs = require("fs");
var mariadb = require('mariadb');
require('dotenv').config();
const pool = mariadb.createPool({
host: 'localhost',
user:'root',
password: 'password',
database: 'Places',
multipleStatements: true,
connectionLimit: 5
});
const serverCert = [fs.readFileSync("skysql_chain_t.pem", "utf8")];
const pool = mariadb.createPool({
host: process.env.DB_HOST,
@ -17,7 +11,10 @@ const pool = mariadb.createPool({
port: process.env.DB_PORT,
database: process.env.DB_NAME,
multipleStatements: true,
connectionLimit: 5
connectionLimit: 5,
ssl: {
ca: serverCert
}
});
module.exports={

Wyświetl plik

@ -16,7 +16,7 @@ router.get("/", async (req, res, next) => {
"then json_value(attr, '$.lastVisitDate') else 'N/A' end) " +
"when type = 'S' then concat((case when json_length(attr, '$.events') is not null " +
"then json_length(attr, '$.events') else 0 end), ' events') end as description " +
"from Locations";
"from locations";
var rows = await conn.query(query);
res.send(rows);
} catch (err) {
@ -32,7 +32,7 @@ router.post("/", async (req, res, next) => {
let conn;
try {
conn = await pool.getConnection();
var query = "insert into Locations (name, description, type, latitude, longitude, attr) values (?, ?, ?, ?, ?, json_compact(?))";
var query = "insert into locations (name, description, type, latitude, longitude, attr) values (?, ?, ?, ?, ?, json_compact(?))";
var result = await conn.query(query, [location.name, location.description, location.type, location.latitude, location.longitude, JSON.stringify(location.attr)]);
res.send(result);
} catch (err) {
@ -54,7 +54,7 @@ router.get("/restaurant", async (req, res, next) => {
"json_value(attr,'$.details.foodType') as foodType, " +
"json_value(attr,'$.details.menu') as menu, " +
"json_query(attr,'$.favorites') as favorites " +
"from Locations " +
"from locations " +
"where id = ?";
var rows = await conn.query(query, [id]);
res.send(rows[0]);
@ -72,7 +72,7 @@ router.post("/restaurant/favorites", async (req, res, next) => {
let conn;
try {
conn = await pool.getConnection();
var query = "update Locations set attr = json_array_append(attr, '$.favorites', json_compact(?)) where id = ?"
var query = "update locations set attr = json_array_append(attr, '$.favorites', json_compact(?)) where id = ?"
var result = await conn.query(query, [JSON.stringify(details), favorite.locationid]);
res.send(result);
} catch (err) {
@ -94,7 +94,7 @@ router.get("/sportsvenue", async (req, res, next) => {
"json_value(attr,'$.details.yearOpened') as yearOpened, " +
"json_value(attr,'$.details.capacity') as capacity, " +
"json_query(attr,'$.events') as events " +
"from Locations " +
"from locations " +
"where id = ?";
var rows = await conn.query(query, [id]);
res.send(rows[0]);
@ -111,7 +111,7 @@ router.post("/sportsvenue/event", async (req, res, next) => {
let conn;
try {
conn = await pool.getConnection();
var query = "update Locations set attr = json_array_append(attr, '$.events', json_compact(?)) where id = ?";
var query = "update locations set attr = json_array_append(attr, '$.events', json_compact(?)) where id = ?";
var result = await conn.query(query, [JSON.stringify(event.details), event.locationid]);
res.send(result);
} catch (err) {
@ -128,7 +128,7 @@ router.put("/attractions", async (req, res, next) => {
let conn;
try {
conn = await pool.getConnection();
var query = "update Locations set attr = json_set(attr,'$.lastVisitDate', ?) where id = ?";
var query = "update locations set attr = json_set(attr,'$.lastVisitDate', ?) where id = ?";
var result = await conn.query(query, [lastVisitDate, locationId]);
res.send(result);
} catch (err) {