gimm285-api-project/server/model/connection.js

21 lines
433 B
JavaScript
Raw Normal View History

2023-04-18 14:41:16 -06:00
const mysql = require('mysql2/promise');
const credentials = require('./creds.json');
let connection = null;
async function query(sql, params) {
2023-04-29 20:48:03 -06:00
console.log(params);
2023-04-18 14:41:16 -06:00
if (null === connection) {
2023-04-29 20:48:03 -06:00
console.log("Establishing connection to database!");
2023-04-18 14:41:16 -06:00
connection = await mysql.createConnection(credentials);
}
const [results, ] = await connection.execute(sql, params);
return results;
}
module.exports = {
query
}