datasquirel/package-shared/utils/backend/global-db/ROOT_DB_HANDLER.ts
2025-01-10 20:10:28 +01:00

42 lines
1018 B
TypeScript

// @ts-check
import mysql from "serverless-mysql";
import grabDbSSL from "../grabDbSSL";
let NO_DB = mysql({
config: {
host: process.env.DSQL_DB_HOST,
user: process.env.DSQL_DB_USERNAME,
password: process.env.DSQL_DB_PASSWORD,
charset: "utf8mb4",
ssl: grabDbSSL(),
},
});
/**
* # Root DB handler
*/
export default function ROOT_DB_HANDLER(...args: any[]) {
try {
return new Promise((resolve, reject) => {
NO_DB.query(...args)
.then((results) => {
NO_DB.end();
resolve(JSON.parse(JSON.stringify(results)));
})
.catch((err) => {
NO_DB.end();
resolve({
error: err.message,
sql: err.sql,
});
});
});
} catch (error: any) {
return {
success: false,
error: error.message,
};
}
}