datasquirel/package-shared/utils/backend/global-db/ROOT_DB_HANDLER.ts

42 lines
1018 B
TypeScript
Raw Normal View History

2024-11-06 06:26:23 +00:00
// @ts-check
2025-01-10 19:10:28 +00:00
import mysql from "serverless-mysql";
import grabDbSSL from "../grabDbSSL";
2024-11-06 06:26:23 +00:00
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",
2024-11-07 14:28:28 +00:00
ssl: grabDbSSL(),
2024-11-06 06:26:23 +00:00
},
});
/**
2025-01-10 19:10:28 +00:00
* # Root DB handler
*/
export default function ROOT_DB_HANDLER(...args: any[]) {
2024-11-06 06:26:23 +00:00
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,
});
});
});
2025-01-10 19:10:28 +00:00
} catch (error: any) {
2024-11-06 06:26:23 +00:00
return {
success: false,
error: error.message,
};
}
}