datasquirel/package-shared/shell/test-external-server.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-12-06 10:31:24 +00:00
require("dotenv").config({ path: "./.env" });
2025-01-10 19:10:28 +00:00
import grabDbSSL from "../utils/backend/grabDbSSL";
import mysql from "serverless-mysql";
2024-12-06 10:31:24 +00:00
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",
ssl: grabDbSSL(),
},
});
/**
* # 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);
2025-01-10 19:10:28 +00:00
} catch (error: any) {
2024-12-06 10:31:24 +00:00
console.log("Connection query ERROR =>", error.message);
} finally {
connection.end();
process.exit();
}
})();