2024-11-05 11:12:42 +00:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
require("dotenv").config({ path: "./.env" });
|
2024-11-06 12:57:20 +00:00
|
|
|
const grabDbSSL = require("../package-shared/utils/backend/grabDbSSL");
|
2024-11-05 11:12:42 +00:00
|
|
|
const mysql = require("serverless-mysql");
|
|
|
|
|
|
|
|
const connection = mysql({
|
|
|
|
config: {
|
|
|
|
host: process.env.DSQL_DB_HOST,
|
|
|
|
user: process.env.DB_USER,
|
|
|
|
password: process.env.DB_PASS,
|
|
|
|
// database: process.env.DSQL_DB_NAME,
|
|
|
|
charset: "utf8mb4",
|
2024-11-06 12:57:20 +00:00
|
|
|
ssl: grabDbSSL(),
|
2024-11-05 11:12:42 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* # Main DB Handler Function
|
|
|
|
* @async
|
|
|
|
*
|
|
|
|
* @param {object} params
|
|
|
|
* @param {string} params.query
|
|
|
|
* @param {string[] | object} [params.values]
|
|
|
|
* @param {string} [params.database]
|
|
|
|
*
|
|
|
|
* @returns {Promise<object|null>}
|
|
|
|
*/
|
|
|
|
(async () => {
|
|
|
|
/**
|
|
|
|
* Switch Database
|
|
|
|
*
|
|
|
|
* @description If a database is provided, switch to it
|
|
|
|
*/
|
|
|
|
try {
|
|
|
|
const result = await connection.query("SHOW DATABASES");
|
|
|
|
|
|
|
|
const parsedResults = JSON.parse(JSON.stringify(result));
|
|
|
|
|
|
|
|
console.log("parsedResults =>", parsedResults);
|
|
|
|
} catch (/** @type {any} */ error) {
|
|
|
|
console.log("Connection query ERROR =>", error.message);
|
|
|
|
} finally {
|
|
|
|
connection.end();
|
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
})();
|