dsql-admin/dsql-app/package-shared/utils/backend/global-db/NO_DB_HANDLER.ts

35 lines
950 B
TypeScript
Raw Normal View History

2025-01-13 08:00:21 +00:00
import mysql from "serverless-mysql";
import grabDbSSL from "../grabDbSSL";
2025-01-14 15:27:08 +00:00
import grabDSQLConnection from "../../grab-dsql-connection";
2025-01-13 08:00:21 +00:00
/**
* # DSQL user read-only DB handler
*/
export default function NO_DB_HANDLER(...args: any[]) {
2025-01-14 15:27:08 +00:00
const CONNECTION = grabDSQLConnection();
2025-01-13 08:00:21 +00:00
try {
return new Promise((resolve, reject) => {
2025-01-14 15:27:08 +00:00
CONNECTION.query(...args)
2025-01-13 08:00:21 +00:00
.then((results) => {
2025-01-14 15:27:08 +00:00
CONNECTION.end();
2025-01-13 08:00:21 +00:00
resolve(JSON.parse(JSON.stringify(results)));
})
.catch((err) => {
2025-01-14 15:27:08 +00:00
CONNECTION.end();
2025-01-13 08:00:21 +00:00
resolve({
error: err.message,
sql: err.sql,
});
});
});
} catch (error: any) {
return {
success: false,
error: error.message,
};
2025-01-14 15:27:08 +00:00
} finally {
CONNECTION?.end();
2025-01-13 08:00:21 +00:00
}
}