Chapter 2: arrow functions

This commit is contained in:
Beth Griggs
2020-05-21 12:45:14 +01:00
parent 85007a6879
commit d8d40e12e5
6 changed files with 14 additions and 21 deletions
+38
View File
@@ -0,0 +1,38 @@
const mysql = require("mysql");
require("dotenv").config();
const db = mysql.createConnection({
user: process.env.DB_MYSQL_USER,
password: process.env.DB_MYSQL_PASSWORD,
});
db.query("CREATE DATABASE tasks");
db.query("USE tasks");
db.query(`
CREATE TABLE tasks.tasks (
id INT NOT NULL AUTO_INCREMENT,
task TEXT NOT NULL, PRIMARY KEY ( id ))
`);
const ignore = new Set(["ER_DB_CREATE_EXISTS", "ER_TABLE_EXISTS_ERROR"]);
db.on("error", (err) => {
if (ignore.has(err.code)) return;
throw err;
});
db.query(`
INSERT INTO tasks.tasks (task)
VALUES ("Walk the dog.");
`);
db.query(
`
SELECT * FROM tasks.tasks;
`,
(err, results, fields) => {
console.log(results);
db.end();
}
);