58 lines
1.8 KiB
JavaScript
Executable File
58 lines
1.8 KiB
JavaScript
Executable File
// @ts-check
|
|
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
|
|
require("dotenv").config({ path: "./../.env" });
|
|
const grabDbSSL = require("../package-shared/utils/backend/grabDbSSL");
|
|
const mysql = require("serverless-mysql");
|
|
|
|
const connection = mysql({
|
|
config: {
|
|
host: process.env.DSQL_DB_HOST,
|
|
user: process.env.DSQL_DB_USERNAME,
|
|
password: process.env.DSQL_DB_PASSWORD,
|
|
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(
|
|
"SELECT id,first_name,last_name FROM users LIMIT 3"
|
|
);
|
|
console.log("Connection Query Success =>", result);
|
|
} catch (/** @type {any} */ error) {
|
|
console.log("Connection query ERROR =>", error.message);
|
|
} finally {
|
|
connection.end();
|
|
process.exit();
|
|
}
|
|
})();
|