Remove all 'useLocal' params
This commit is contained in:
@@ -21,32 +21,10 @@ type Param = {
|
||||
update?: boolean;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
useLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a db Entry Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {("Master" | "Dsql User")} [params.dbContext] - What is the database context? "Master"
|
||||
* or "Dsql User". Defaults to "Master"
|
||||
* @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"?
|
||||
* "Read only" or "Full Access"? Defaults to "Read Only"
|
||||
* @param {string} [params.dbFullName] - Database full name
|
||||
* @param {string} params.tableName - Table name
|
||||
* @param {any} params.data - Data to add
|
||||
* @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @param {string} [params.duplicateColumnName] - Duplicate column name
|
||||
* @param {string} [params.duplicateColumnValue] - Duplicate column value
|
||||
* @param {boolean} [params.update] - Update this row if it exists
|
||||
* @param {string} [params.encryptionKey] - Update this row if it exists
|
||||
* @param {string} [params.encryptionSalt] - Update this row if it exists
|
||||
* @param {boolean} [params.useLocal]
|
||||
*
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export default async function addDbEntry({
|
||||
dbContext,
|
||||
@@ -60,12 +38,11 @@ export default async function addDbEntry({
|
||||
update,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
useLocal,
|
||||
}: Param): Promise<any> {
|
||||
/**
|
||||
* Initialize variables
|
||||
*/
|
||||
const isMaster = useLocal
|
||||
const isMaster = global.DSQL_USE_LOCAL
|
||||
? true
|
||||
: dbContext?.match(/dsql.user/i)
|
||||
? false
|
||||
@@ -74,7 +51,7 @@ export default async function addDbEntry({
|
||||
: true;
|
||||
|
||||
/** @type { any } */
|
||||
const dbHandler: any = useLocal
|
||||
const dbHandler: any = global.DSQL_USE_LOCAL
|
||||
? LOCAL_DB_HANDLER
|
||||
: isMaster
|
||||
? DB_HANDLER
|
||||
|
||||
@@ -10,7 +10,6 @@ type Param = {
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
useLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -24,10 +23,9 @@ export default async function deleteDbEntry({
|
||||
tableName,
|
||||
identifierColumnName,
|
||||
identifierValue,
|
||||
useLocal,
|
||||
}: Param): Promise<object | null> {
|
||||
try {
|
||||
const isMaster = useLocal
|
||||
const isMaster = global.DSQL_USE_LOCAL
|
||||
? true
|
||||
: dbContext?.match(/dsql.user/i)
|
||||
? false
|
||||
@@ -35,8 +33,7 @@ export default async function deleteDbEntry({
|
||||
? false
|
||||
: true;
|
||||
|
||||
/** @type { (a1:any, a2?:any) => any } */
|
||||
const dbHandler: (a1: any, a2?: any) => any = useLocal
|
||||
const dbHandler: (a1: any, a2?: any) => any = global.DSQL_USE_LOCAL
|
||||
? LOCAL_DB_HANDLER
|
||||
: isMaster
|
||||
? DB_HANDLER
|
||||
|
||||
@@ -11,7 +11,6 @@ type Param = {
|
||||
dbFullName: string;
|
||||
query: string | any;
|
||||
readOnly?: boolean;
|
||||
local?: boolean;
|
||||
debug?: boolean;
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
queryValuesArray?: (string | number)[];
|
||||
@@ -28,7 +27,6 @@ export default async function runQuery({
|
||||
dbSchema,
|
||||
queryValuesArray,
|
||||
tableName,
|
||||
local,
|
||||
debug,
|
||||
}: Param): Promise<any> {
|
||||
/**
|
||||
@@ -68,7 +66,7 @@ export default async function runQuery({
|
||||
if (typeof query === "string") {
|
||||
const formattedQuery = trimSql(query);
|
||||
|
||||
if (debug && local) {
|
||||
if (debug && global.DSQL_USE_LOCAL) {
|
||||
console.log("runQuery:formattedQuery", formattedQuery);
|
||||
}
|
||||
|
||||
@@ -91,14 +89,12 @@ export default async function runQuery({
|
||||
queryString: formattedQuery,
|
||||
queryValuesArray: queryValuesArray?.map((vl) => String(vl)),
|
||||
tableSchema,
|
||||
useLocal: local,
|
||||
});
|
||||
} else {
|
||||
result = await fullAccessDbHandler({
|
||||
queryString: formattedQuery,
|
||||
queryValuesArray: queryValuesArray?.map((vl) => String(vl)),
|
||||
tableSchema,
|
||||
local,
|
||||
});
|
||||
}
|
||||
} else if (typeof query === "object") {
|
||||
@@ -121,7 +117,9 @@ export default async function runQuery({
|
||||
switch (action.toLowerCase()) {
|
||||
case "insert":
|
||||
result = await addDbEntry({
|
||||
dbContext: local ? "Master" : "Dsql User",
|
||||
dbContext: global.DSQL_USE_LOCAL
|
||||
? "Master"
|
||||
: "Dsql User",
|
||||
paradigm: "Full Access",
|
||||
dbFullName: dbFullName,
|
||||
tableName: table,
|
||||
@@ -130,7 +128,6 @@ export default async function runQuery({
|
||||
duplicateColumnName,
|
||||
duplicateColumnValue,
|
||||
tableSchema,
|
||||
useLocal: local,
|
||||
});
|
||||
|
||||
if (!result?.insertId) {
|
||||
@@ -141,7 +138,9 @@ export default async function runQuery({
|
||||
|
||||
case "update":
|
||||
result = await updateDbEntry({
|
||||
dbContext: local ? "Master" : "Dsql User",
|
||||
dbContext: global.DSQL_USE_LOCAL
|
||||
? "Master"
|
||||
: "Dsql User",
|
||||
paradigm: "Full Access",
|
||||
dbFullName: dbFullName,
|
||||
tableName: table,
|
||||
@@ -149,21 +148,21 @@ export default async function runQuery({
|
||||
identifierColumnName,
|
||||
identifierValue,
|
||||
tableSchema,
|
||||
useLocal: local,
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
result = await deleteDbEntry({
|
||||
dbContext: local ? "Master" : "Dsql User",
|
||||
dbContext: global.DSQL_USE_LOCAL
|
||||
? "Master"
|
||||
: "Dsql User",
|
||||
paradigm: "Full Access",
|
||||
dbFullName: dbFullName,
|
||||
tableName: table,
|
||||
identifierColumnName,
|
||||
identifierValue,
|
||||
tableSchema,
|
||||
useLocal: local,
|
||||
});
|
||||
|
||||
break;
|
||||
@@ -179,7 +178,7 @@ export default async function runQuery({
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
if (debug && local) {
|
||||
if (debug && global.DSQL_USE_LOCAL) {
|
||||
console.log("runQuery:error", error.message);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ type Param = {
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
useLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -34,14 +33,13 @@ export default async function updateDbEntry({
|
||||
identifierValue,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
useLocal,
|
||||
}: Param): Promise<object | null> {
|
||||
/**
|
||||
* Check if data is valid
|
||||
*/
|
||||
if (!data || !Object.keys(data).length) return null;
|
||||
|
||||
const isMaster = useLocal
|
||||
const isMaster = global.DSQL_USE_LOCAL
|
||||
? true
|
||||
: dbContext?.match(/dsql.user/i)
|
||||
? false
|
||||
@@ -50,7 +48,7 @@ export default async function updateDbEntry({
|
||||
: true;
|
||||
|
||||
/** @type {(a1:any, a2?:any)=> any } */
|
||||
const dbHandler: (a1: any, a2?: any) => any = useLocal
|
||||
const dbHandler: (a1: any, a2?: any) => any = global.DSQL_USE_LOCAL
|
||||
? LOCAL_DB_HANDLER
|
||||
: isMaster
|
||||
? DB_HANDLER
|
||||
|
||||
Reference in New Issue
Block a user