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

32 lines
798 B
TypeScript
Raw Normal View History

2025-01-13 08:00:21 +00:00
import connDbHandler from "../../db/conn-db-handler";
2025-01-14 15:27:08 +00:00
import grabDSQLConnection from "../../grab-dsql-connection";
2025-01-13 08:00:21 +00:00
type Param = {
paradigm: "Full Access" | "FA" | "Read Only";
queryString: string;
queryValues?: string[];
};
/**
* # DSQL user read-only DB handler
*/
export default async function DSQL_USER_DB_HANDLER({
paradigm,
queryString,
queryValues,
}: Param) {
2025-01-14 15:27:08 +00:00
const CONNECTION =
paradigm == "Read Only"
? grabDSQLConnection({ ro: true })
: grabDSQLConnection({ fa: true });
2025-01-13 08:00:21 +00:00
2025-01-14 15:27:08 +00:00
try {
return await connDbHandler(CONNECTION, queryString, queryValues);
2025-01-13 08:00:21 +00:00
} catch (error: any) {
console.log(`DSQL_USER_DB_HANDLER Error: ${error.message}`);
return null;
2025-01-14 15:27:08 +00:00
} finally {
CONNECTION?.end();
2025-01-13 08:00:21 +00:00
}
}