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

32 lines
825 B
TypeScript
Raw Normal View History

2025-01-13 08:00:21 +00:00
import mysql from "serverless-mysql";
import grabDbSSL from "../grabDbSSL";
/**
* # DSQL user read-only DB handler
*/
export default function NO_DB_HANDLER(...args: any[]) {
const NO_DB = global.DSQL_DB_CONN;
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,
};
}
}