Updates
This commit is contained in:
@@ -1,22 +1,12 @@
|
||||
import mysql from "serverless-mysql";
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
|
||||
/**
|
||||
* # DSQL user read-only DB handler
|
||||
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||
*/
|
||||
export default async function DB_HANDLER(...args: any[]) {
|
||||
const CONNECTION = mysql({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
password: process.env.DSQL_DB_PASSWORD,
|
||||
database: process.env.DSQL_DB_NAME,
|
||||
port: process.env.DSQL_DB_PORT
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
},
|
||||
});
|
||||
const CONNECTION = grabDSQLConnection();
|
||||
|
||||
try {
|
||||
if (!CONNECTION)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import mysql from "serverless-mysql";
|
||||
import connDbHandler from "../../db/conn-db-handler";
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
|
||||
type Param = {
|
||||
paradigm: "Full Access" | "FA" | "Read Only";
|
||||
@@ -17,28 +17,8 @@ export default async function DSQL_USER_DB_HANDLER({
|
||||
}: Param) {
|
||||
const CONNECTION =
|
||||
paradigm == "Read Only"
|
||||
? mysql({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_READ_ONLY_USERNAME,
|
||||
password: process.env.DSQL_DB_READ_ONLY_PASSWORD,
|
||||
port: process.env.DSQL_DB_PORT
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
},
|
||||
})
|
||||
: mysql({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_FULL_ACCESS_USERNAME,
|
||||
password: process.env.DSQL_DB_FULL_ACCESS_PASSWORD,
|
||||
port: process.env.DSQL_DB_PORT
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
},
|
||||
});
|
||||
? grabDSQLConnection({ ro: true })
|
||||
: grabDSQLConnection({ fa: true });
|
||||
|
||||
try {
|
||||
return await connDbHandler(CONNECTION, queryString, queryValues);
|
||||
@@ -48,92 +28,4 @@ export default async function DSQL_USER_DB_HANDLER({
|
||||
} finally {
|
||||
CONNECTION?.end();
|
||||
}
|
||||
|
||||
// try {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// const fullAccess = paradigm?.match(/full.access|^fa$/i)
|
||||
// ? true
|
||||
// : false;
|
||||
|
||||
// try {
|
||||
// if (fullAccess) {
|
||||
// DSQL_USER = mysql({
|
||||
// config: {
|
||||
// host: process.env.DSQL_DB_HOST,
|
||||
// user: process.env.DSQL_DB_FULL_ACCESS_USERNAME,
|
||||
// password: process.env.DSQL_DB_FULL_ACCESS_PASSWORD,
|
||||
// database: database,
|
||||
// ssl: grabDbSSL(),
|
||||
// },
|
||||
// });
|
||||
// } else {
|
||||
// DSQL_USER = mysql({
|
||||
// config: {
|
||||
// host: process.env.DSQL_DB_HOST,
|
||||
// user: process.env.DSQL_DB_READ_ONLY_USERNAME,
|
||||
// password: process.env.DSQL_DB_READ_ONLY_PASSWORD,
|
||||
// database: database,
|
||||
// ssl: grabDbSSL(),
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * ### Run query Function
|
||||
// * @param {any} results
|
||||
// */
|
||||
// function runQuery(results: any) {
|
||||
// DSQL_USER.end();
|
||||
// resolve(JSON.parse(JSON.stringify(results)));
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * ### Query Error
|
||||
// * @param {any} err
|
||||
// */
|
||||
// function queryError(err: any) {
|
||||
// DSQL_USER.end();
|
||||
// resolve({
|
||||
// error: err.message,
|
||||
// queryStringGenerated: queryString,
|
||||
// queryValuesGenerated: queryValues,
|
||||
// sql: err.sql,
|
||||
// });
|
||||
// }
|
||||
|
||||
// if (
|
||||
// queryValues &&
|
||||
// Array.isArray(queryValues) &&
|
||||
// queryValues[0]
|
||||
// ) {
|
||||
// DSQL_USER.query(queryString, queryValues)
|
||||
// .then(runQuery)
|
||||
// .catch(queryError);
|
||||
// } else {
|
||||
// DSQL_USER.query(queryString)
|
||||
// .then(runQuery)
|
||||
// .catch(queryError);
|
||||
// }
|
||||
|
||||
// ////////////////////////////////////////
|
||||
// } catch (/** @type {any} */ error: any) {
|
||||
// ////////////////////////////////////////
|
||||
|
||||
// fs.appendFileSync(
|
||||
// "./.tmp/dbErrorLogs.txt",
|
||||
// error.message + "\n" + Date() + "\n\n\n",
|
||||
// "utf8"
|
||||
// );
|
||||
|
||||
// resolve({
|
||||
// error: error.message,
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// } catch (/** @type {any} */ error: any) {
|
||||
// return {
|
||||
// success: false,
|
||||
// error: error.message,
|
||||
// };
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,45 +1,24 @@
|
||||
import mysql from "serverless-mysql";
|
||||
import grabDbSSL from "../grabDbSSL";
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
|
||||
/**
|
||||
* # DSQL user read-only DB handler
|
||||
*/
|
||||
export default async function LOCAL_DB_HANDLER(...args: any[]) {
|
||||
const MASTER = mysql({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
password: process.env.DSQL_DB_PASSWORD,
|
||||
database: process.env.DSQL_DB_NAME,
|
||||
port: process.env.DSQL_DB_PORT
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
ssl: grabDbSSL(),
|
||||
},
|
||||
onConnect: () => {
|
||||
console.log("Connection Successful!");
|
||||
},
|
||||
onConnectError: (/** @type {any} */ err: any) => {
|
||||
console.log("Connection Error", err.message);
|
||||
},
|
||||
onError: (/** @type {any} */ err: any) => {
|
||||
console.log("Client Error", err.message);
|
||||
},
|
||||
});
|
||||
const MASTER = grabDSQLConnection();
|
||||
|
||||
console.log("Querying ...");
|
||||
|
||||
try {
|
||||
const results = await MASTER.query(...args);
|
||||
await MASTER.end();
|
||||
|
||||
return JSON.parse(JSON.stringify(results));
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
} catch (error: any) {
|
||||
console.log("DB Error =>", error.message);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
} finally {
|
||||
await MASTER?.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
import mysql from "serverless-mysql";
|
||||
import grabDbSSL from "../grabDbSSL";
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
|
||||
/**
|
||||
* # DSQL user read-only DB handler
|
||||
*/
|
||||
export default function NO_DB_HANDLER(...args: any[]) {
|
||||
const CONNECTION = mysql({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
password: process.env.DSQL_DB_PASSWORD,
|
||||
database: process.env.DSQL_DB_NAME,
|
||||
port: process.env.DSQL_DB_PORT
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
},
|
||||
});
|
||||
const CONNECTION = grabDSQLConnection();
|
||||
|
||||
try {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -1,21 +1,10 @@
|
||||
import mysql from "serverless-mysql";
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
|
||||
/**
|
||||
* # Root DB handler
|
||||
*/
|
||||
export default function ROOT_DB_HANDLER(...args: any[]) {
|
||||
const CONNECTION = mysql({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
password: process.env.DSQL_DB_PASSWORD,
|
||||
database: process.env.DSQL_DB_NAME,
|
||||
port: process.env.DSQL_DB_PORT
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
},
|
||||
});
|
||||
const CONNECTION = grabDSQLConnection();
|
||||
|
||||
try {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user