diff options
author | JoelHMikael <joel.h.kronqvist@gmail.com> | 2022-01-07 10:58:02 +0200 |
---|---|---|
committer | JoelHMikael <joel.h.kronqvist@gmail.com> | 2022-01-07 10:58:02 +0200 |
commit | 4e5fe4711fe46a6af740aadbf23bde86bb5acf69 (patch) | |
tree | a6c11bbdda6d6f42848961b19c365db0c91cb4b8 | |
parent | e7b4d365f287f173c8cc0b5a4d965c3a0579c2e0 (diff) | |
download | LYLLRuoka-4e5fe4711fe46a6af740aadbf23bde86bb5acf69.tar.gz LYLLRuoka-4e5fe4711fe46a6af740aadbf23bde86bb5acf69.zip |
Added the DB class & instructions to set up DB
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | database.js | 37 | ||||
-rw-r--r-- | index.html | 2 | ||||
-rw-r--r-- | server.js | 1 |
4 files changed, 47 insertions, 2 deletions
@@ -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; @@ -8,7 +8,7 @@ </head> <body> <header> - <h1 class="shadow">LYLL-ruokailuvuoro</h1> + <h1 class="shadow">LYLL-ruoka</h1> </header> <br> @@ -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() |