Updates
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import { DbContextsArray } from "./runQuery";
|
||||
type Param = {
|
||||
import { PostInsertReturn } from "../../../types";
|
||||
type Param<T extends {
|
||||
[k: string]: any;
|
||||
} = any> = {
|
||||
dbContext?: (typeof DbContextsArray)[number];
|
||||
paradigm?: "Read Only" | "Full Access";
|
||||
dbFullName?: string;
|
||||
tableName: string;
|
||||
data: any;
|
||||
data: T;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
duplicateColumnName?: string;
|
||||
duplicateColumnValue?: string;
|
||||
@@ -17,5 +20,7 @@ type Param = {
|
||||
/**
|
||||
* Add a db Entry Function
|
||||
*/
|
||||
export default function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, forceLocal, debug, }: Param): Promise<any>;
|
||||
export default function addDbEntry<T extends {
|
||||
[k: string]: any;
|
||||
} = any>({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, forceLocal, debug, }: Param<T>): Promise<PostInsertReturn | null>;
|
||||
export {};
|
||||
|
||||
@@ -26,9 +26,6 @@ const debug_log_1 = __importDefault(require("../../../utils/logging/debug-log"))
|
||||
function addDbEntry(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, forceLocal, debug, }) {
|
||||
var _b, _c, _d;
|
||||
/**
|
||||
* Initialize variables
|
||||
*/
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: (0, check_if_is_master_1.default)({ dbContext, dbFullName });
|
||||
@@ -45,9 +42,6 @@ function addDbEntry(_a) {
|
||||
const DB_RO_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
if (data === null || data === void 0 ? void 0 : data["date_created_timestamp"])
|
||||
delete data["date_created_timestamp"];
|
||||
if (data === null || data === void 0 ? void 0 : data["date_updated_timestamp"])
|
||||
@@ -60,9 +54,6 @@ function addDbEntry(_a) {
|
||||
delete data["date_created"];
|
||||
if (data === null || data === void 0 ? void 0 : data["date_created_code"])
|
||||
delete data["date_created_code"];
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
if (duplicateColumnName && typeof duplicateColumnName === "string") {
|
||||
const checkDuplicateQuery = `SELECT * FROM ${isMaster ? "" : `\`${dbFullName}\`.`}\`${tableName}\` WHERE \`${duplicateColumnName}\`=?`;
|
||||
const duplicateValue = yield (0, conn_db_handler_1.default)(DB_RO_CONN, checkDuplicateQuery, [duplicateColumnValue]);
|
||||
@@ -83,18 +74,12 @@ function addDbEntry(_a) {
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
const dataKeys = Object.keys(data);
|
||||
let insertKeysArray = [];
|
||||
let insertValuesArray = [];
|
||||
for (let i = 0; i < dataKeys.length; i++) {
|
||||
try {
|
||||
const dataKey = dataKeys[i];
|
||||
// @ts-ignore
|
||||
let value = data === null || data === void 0 ? void 0 : data[dataKey];
|
||||
const targetFieldSchemaArray = tableSchema
|
||||
? (_b = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _b === void 0 ? void 0 : _b.filter((field) => field.fieldName == dataKey)
|
||||
@@ -144,7 +129,6 @@ function addDbEntry(_a) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////
|
||||
if (!(data === null || data === void 0 ? void 0 : data["date_created"])) {
|
||||
insertKeysArray.push("`date_created`");
|
||||
insertValuesArray.push(Date());
|
||||
@@ -153,7 +137,6 @@ function addDbEntry(_a) {
|
||||
insertKeysArray.push("`date_created_code`");
|
||||
insertValuesArray.push(Date.now());
|
||||
}
|
||||
////////////////////////////////////////
|
||||
if (!(data === null || data === void 0 ? void 0 : data["date_updated"])) {
|
||||
insertKeysArray.push("`date_updated`");
|
||||
insertValuesArray.push(Date());
|
||||
@@ -162,7 +145,6 @@ function addDbEntry(_a) {
|
||||
insertKeysArray.push("`date_updated_code`");
|
||||
insertValuesArray.push(Date.now());
|
||||
}
|
||||
////////////////////////////////////////
|
||||
const query = `INSERT INTO ${isMaster ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${insertKeysArray.join(",")}) VALUES (${insertValuesArray
|
||||
.map(() => "?")
|
||||
.join(",")})`;
|
||||
@@ -192,9 +174,6 @@ function addDbEntry(_a) {
|
||||
label: "newInsert",
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
return newInsert;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { DbContextsArray } from "./runQuery";
|
||||
type Param = {
|
||||
import { PostInsertReturn } from "../../../types";
|
||||
type Param<T extends {
|
||||
[k: string]: any;
|
||||
} = any> = {
|
||||
dbContext?: (typeof DbContextsArray)[number];
|
||||
dbFullName?: string;
|
||||
tableName: string;
|
||||
@@ -7,7 +10,7 @@ type Param = {
|
||||
encryptionSalt?: string;
|
||||
data: any;
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierColumnName: keyof T;
|
||||
identifierValue: string | number;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
@@ -15,5 +18,7 @@ type Param = {
|
||||
* # Update DB Function
|
||||
* @description
|
||||
*/
|
||||
export default function updateDbEntry({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, forceLocal, }: Param): Promise<object | null>;
|
||||
export default function updateDbEntry<T extends {
|
||||
[k: string]: any;
|
||||
} = any>({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, forceLocal, }: Param<T>): Promise<PostInsertReturn | null>;
|
||||
export {};
|
||||
|
||||
Reference in New Issue
Block a user