This commit is contained in:
Benjamin Toby
2025-02-12 17:56:44 +01:00
parent a5c3d59d24
commit 1b48c07ee8
431 changed files with 1665 additions and 827 deletions
@@ -19,6 +19,7 @@ type Param = {
update?: boolean;
encryptionKey?: string;
encryptionSalt?: string;
forceLocal?: boolean;
};
/**
@@ -36,11 +37,14 @@ export default async function addDbEntry({
update,
encryptionKey,
encryptionSalt,
forceLocal,
}: Param): Promise<any> {
/**
* Initialize variables
*/
const isMaster = checkIfIsMaster({ dbContext, dbFullName });
const isMaster = forceLocal
? true
: checkIfIsMaster({ dbContext, dbFullName });
const DB_CONN = isMaster
? global.DSQL_DB_CONN
@@ -9,6 +9,7 @@ type Param = {
tableSchema?: import("../../../types").DSQL_TableSchemaType;
identifierColumnName: string;
identifierValue: string | number;
forceLocal?: boolean;
};
/**
@@ -21,9 +22,12 @@ export default async function deleteDbEntry({
tableName,
identifierColumnName,
identifierValue,
forceLocal,
}: Param): Promise<object | null> {
try {
const isMaster = checkIfIsMaster({ dbContext, dbFullName });
const isMaster = forceLocal
? true
: checkIfIsMaster({ dbContext, dbFullName });
const DB_CONN = isMaster
? global.DSQL_DB_CONN
@@ -18,6 +18,12 @@ type Param = {
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
queryValuesArray?: (string | number)[];
tableName?: string;
forceLocal?: boolean;
};
type Return = {
result: any;
error?: string;
};
/**
@@ -32,7 +38,8 @@ export default async function runQuery({
tableName,
debug,
dbContext,
}: Param): Promise<any> {
forceLocal,
}: Param): Promise<Return> {
/**
* Declare variables
*
@@ -40,7 +47,7 @@ export default async function runQuery({
*/
let result: any;
let error: any;
let error: string | undefined;
let tableSchema: DSQL_TableSchemaType | undefined;
if (dbSchema) {
@@ -79,12 +86,7 @@ export default async function runQuery({
*
* @description Input Validation
*/
if (
readOnly &&
formattedQuery.match(
/^alter|^delete|information_schema|^create/i
)
) {
if (readOnly && formattedQuery.match(/^alter|^delete|^create/i)) {
throw new Error("Wrong Input!");
}
@@ -93,12 +95,14 @@ export default async function runQuery({
queryString: formattedQuery,
queryValuesArray: queryValuesArray?.map((vl) => String(vl)),
tableSchema,
forceLocal,
});
} else {
result = await fullAccessDbHandler({
queryString: formattedQuery,
queryValuesArray: queryValuesArray?.map((vl) => String(vl)),
tableSchema,
forceLocal,
});
}
} else if (typeof query === "object") {
@@ -132,7 +136,7 @@ export default async function runQuery({
});
if (!result?.insertId) {
error = new Error("Couldn't insert data");
error = "Couldn't insert data";
}
break;
@@ -167,18 +171,18 @@ export default async function runQuery({
break;
}
}
} catch (error: any) {
} catch (err: any) {
serverError({
component: "functions/backend/runQuery",
message: error.message,
message: err.message,
});
if (debug && global.DSQL_USE_LOCAL) {
console.log("runQuery:error", error.message);
console.log("runQuery:error", err.message);
}
result = null;
error = error.message;
error = err.message;
}
return { result, error };
@@ -15,6 +15,7 @@ type Param = {
tableSchema?: import("../../../types").DSQL_TableSchemaType;
identifierColumnName: string;
identifierValue: string | number;
forceLocal?: boolean;
};
/**
@@ -31,13 +32,16 @@ export default async function updateDbEntry({
identifierValue,
encryptionKey,
encryptionSalt,
forceLocal,
}: Param): Promise<object | null> {
/**
* Check if data is valid
*/
if (!data || !Object.keys(data).length) return null;
const isMaster = checkIfIsMaster({ dbContext, dbFullName });
const isMaster = forceLocal
? true
: checkIfIsMaster({ dbContext, dbFullName });
const DB_CONN = isMaster
? global.DSQL_DB_CONN