From e67fd83b4d6abe55931d00d7f2d13ec37cb909c7 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 29 Nov 2021 19:37:52 -0500 Subject: [PATCH] change to connect db for each function as needed --- functions.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/functions.js b/functions.js index f1cebda..3b143ec 100644 --- a/functions.js +++ b/functions.js @@ -33,7 +33,6 @@ const db = new mysql.createConnection({ database: dbName, port: dbPort, }); -db.connect(); const functions = { collections: { @@ -332,65 +331,82 @@ const functions = { upload: { request(commandData, client) { const query = `INSERT INTO requests (author, request, status) VALUES ('${commandData.author}','${commandData.args}','Active')`; + db.connect(); db.query(query, (err, rows, fields) => { if (err) throw err; functions.download.requests(client); }); + db.end(); }, pasta(pastaData, client) { const query = `INSERT INTO pastas (name, content) VALUES ('${pastaData.name}','${pastaData.content}')`; + db.connect(); db.query(query, (err, rows, fields) => { if (err) throw err; functions.download.pastas(client); }); + db.end(); }, joint(content, client) { const query = `INSERT INTO joints (content) VALUES ('${content}')`; + db.connect(); db.query(query, (err, rows, fields) => { if (err) throw err; functions.download.joints(client); }); + db.end(); }, gif(gifData, client) { const query = `INSERT INTO gifs (name, embed_url) VALUES ('${gifData.name}', '${gifData.embed_url}')`; + db.connect(); db.query(query, (err, rows, fields) => { if (err) throw err; functions.download.gifs(client); }); + db.end(); } }, download: { requests(client) { const query = 'SELECT * FROM requests WHERE status = \'Active\' ORDER BY id ASC'; + db.connect(); db.query(query, (err, rows, fields) => { if (err) throw err; functions.collections.requests(rows, client); }); + db.end(); }, pastas(client) { const query = 'SELECT * FROM pastas ORDER BY id ASC'; + db.connect(); db.query(query, (err, rows, fields) => { if (err) throw err; functions.collections.pastas(rows, client); }); + db.end(); }, gifs(client) { const query = 'SELECT * FROM gifs ORDER BY id ASC'; + db.connect(); db.query(query, (err, rows, fields) => { if (err) throw err; functions.collections.gifs(rows, client); }); + db.end(); }, joints(client) { const query = 'SELECT * FROM joints ORDER BY id ASC'; + db.connect(); db.query(query, (err, rows, fields) => { if (err) throw err; functions.collections.joints(rows, client); }); + db.end(); }, strain(commandData, message) { const { strainName } = commandData; const query = `SELECT id, name, type, effects, ailment, flavor FROM strains WHERE name = '${strainName}'`; + db.connect(); db.query(query, (err, rows, fields) => { if (rows != undefined) { commandData.strainInfo = { @@ -404,13 +420,16 @@ const functions = { functions.embeds.strain(commandData, message); } }); + db.end(); }, strains(client) { const query = 'SELECT id, name FROM strains'; + db.connect(); db.query(query, (err, rows, fields) => { if (err) throw err; functions.collections.strains(rows, client); }); + db.end(); }, }, weed: { @@ -432,10 +451,12 @@ const functions = { // Parent-Level functions (miscellaneuous) closeRequest(requestId, client) { const query = `UPDATE requests SET status = 'Closed' WHERE id = ${requestId}`; + db.connect(); db.query(query, (err, rows, fields) => { if (err) throw err; functions.download.requests(client); }); + db.end(); }, spongebob(commandData) { let flipper = 0;