From 87e0f74453a36cb607e55115c0e70c3d685ea97a Mon Sep 17 00:00:00 2001 From: FireInjun Date: Tue, 4 Sep 2018 17:41:55 -0400 Subject: [PATCH 1/2] INIT FOR PR 9/4/2018 5:41 PM --- INIT | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 INIT diff --git a/INIT b/INIT new file mode 100644 index 0000000..e69de29 From d17c71558eda58c1131271981b9b36dec6656a0c Mon Sep 17 00:00:00 2001 From: FireInjun Date: Thu, 1 Nov 2018 18:47:28 -0400 Subject: [PATCH 2/2] 11/1/2018 6:47 PM --- solutions/earthquake.js | 13 +++++++------ solutions/maketable.js | 27 +++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/solutions/earthquake.js b/solutions/earthquake.js index 6d32499..d55f563 100644 --- a/solutions/earthquake.js +++ b/solutions/earthquake.js @@ -1,8 +1,8 @@ -const { Client } = require('pg'); +const { Client } = require("pg"); /** * Does the heavy lifting. - * + * * Function is async so we can use await. */ async function run(mag) { @@ -26,14 +26,15 @@ async function run(mag) { const res = await client.query(query, [mag]); // Print the results - console.log(`Earthquakes with magnitudes greater than or equal to ${mag}:\n`); + console.log( + `Earthquakes with magnitudes greater than or equal to ${mag}:\n` + ); for (let row of res.rows) { - console.log(`${row.name}: ${row.magnitude}`); + console.log(`${row.name}: ${row.magnitude}`); } await client.end(); - } catch (err) { console.log(err); } @@ -60,4 +61,4 @@ if (isNaN(mag)) { usageExit(); } -run(mag); \ No newline at end of file +run(mag); diff --git a/solutions/maketable.js b/solutions/maketable.js index 81f6c66..1d296b8 100644 --- a/solutions/maketable.js +++ b/solutions/maketable.js @@ -1,8 +1,8 @@ -const { Client } = require('pg'); +const { Client } = require("pg"); /** * Does the heavy lifting. - * + * * Function is async so we can use await. */ async function run() { @@ -17,36 +17,35 @@ async function run() { try { // Connect to DB await client.connect(); - + // Create table await client.query(`CREATE TABLE IF NOT EXISTS Earthquake (Name VARCHAR(20), Magnitude REAL)`); // Clear out the table if it already existed // Sometimes you want to do this, sometimes you don't. - await client.query('DELETE FROM Earthquake'); + await client.query("DELETE FROM Earthquake"); // Insert new data let data = [ - ["Earthquake 1", 2.2], - ["Earthquake 2", 7.0], - ["Earthquake 3", 1.8], - ["Earthquake 4", 5.2], - ["Earthquake 5", 2.9], - ["Earthquake 6", 0.6], - ["Earthquake 7", 6.6] + ["Earthquake 1", 2.2], + ["Earthquake 2", 7.0], + ["Earthquake 3", 1.8], + ["Earthquake 4", 5.2], + ["Earthquake 5", 2.9], + ["Earthquake 6", 0.6], + ["Earthquake 7", 6.6] ]; - const query = 'INSERT INTO Earthquake(Name, Magnitude) VALUES($1, $2)'; + const query = "INSERT INTO Earthquake(Name, Magnitude) VALUES($1, $2)"; for (let record of data) { await client.query(query, record); } await client.end(); - } catch (err) { console.log(err); } } -run(); \ No newline at end of file +run();