From 4e5fe4711fe46a6af740aadbf23bde86bb5acf69 Mon Sep 17 00:00:00 2001 From: JoelHMikael Date: Fri, 7 Jan 2022 10:58:02 +0200 Subject: Added the DB class & instructions to set up DB --- README.md | 9 ++++++++- database.js | 37 +++++++++++++++++++++++++++++++++++++ index.html | 2 +- server.js | 1 + 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 database.js diff --git a/README.md b/README.md index f118d5f..7c60f52 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,11 @@ Readme coming soon! ## Setup -If you want to set up the server, you will have to get a SSL certificate or generate one yourself. If you want to run a dedicated server that can update, you also need to add the cron jobs from crontab\_add. +If you want to set up the server, you will have to get a SSL certificate or generate one yourself. If you want to run a dedicated server that can update, you also need to add the cron jobs from crontab\_add. You must create a MySQL DB and give its login info in ../dblogin.txt. The database should have the following tables set up: + +CREATE TABLE devs ( + id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(30) NOT NULL, + description VARCHAR(128), + contact VARCHAR(40) +); diff --git a/database.js b/database.js new file mode 100644 index 0000000..3a2822a --- /dev/null +++ b/database.js @@ -0,0 +1,37 @@ +class Database +{ + constructor(credentials, log) + { + this.connection = mysql.createConnection(credentials); + this.log = log; + } + query(q) + { + return new Promise((resolve, reject), () => + { + this.connection.query(q, (err, res, fields) => + { + if (err) + { + this.log(err); + reject(err); + } + resolve(res); + }); + }); + } + close() + { + this.connection.end(err => + { + if (err) + { + this.log(err); + reject(err); + } + resolve(); + }); + } +} + +exports.Database = Database; diff --git a/index.html b/index.html index c9f6c4c..90e4a9b 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@
-

LYLL-ruokailuvuoro

+

LYLL-ruoka


diff --git a/server.js b/server.js index d26da04..4b1e8a3 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,7 @@ const fs = require("fs"); const url = require("url"); const parse = require("./parse.js"); const scrape = require("./scrape.js"); +const mysql = require("mysql2"); async function init() -- cgit v1.2.3