diff --git a/INIT b/INIT new file mode 100644 index 0000000..e69de29 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();