Updates
This commit is contained in:
@@ -70,6 +70,7 @@ function apiPost(_a) {
|
||||
delete clonedTargetTable.childrenTables;
|
||||
delete clonedTargetTable.updateData;
|
||||
delete clonedTargetTable.indexes;
|
||||
delete clonedTargetTable.uniqueConstraints;
|
||||
tableSchema = clonedTargetTable;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-27
@@ -1,32 +1,7 @@
|
||||
import { DbContextsArray } from "./runQuery";
|
||||
import { APIResponseObject, DSQL_TableSchemaType, PostInsertReturn } from "../../../types";
|
||||
import { ConnectionConfig } from "mariadb";
|
||||
export type AddDbEntryParam<T extends {
|
||||
[k: string]: any;
|
||||
} = any, K extends string = string> = {
|
||||
dbContext?: (typeof DbContextsArray)[number];
|
||||
paradigm?: "Read Only" | "Full Access";
|
||||
dbFullName?: string;
|
||||
tableName: K;
|
||||
data?: T;
|
||||
batchData?: T[];
|
||||
tableSchema?: DSQL_TableSchemaType;
|
||||
duplicateColumnName?: keyof T;
|
||||
duplicateColumnValue?: string | number;
|
||||
/**
|
||||
* Update Entry if a duplicate is found.
|
||||
* Requires `duplicateColumnName` and `duplicateColumnValue` parameters
|
||||
*/
|
||||
update?: boolean;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
forceLocal?: boolean;
|
||||
debug?: boolean;
|
||||
dbConfig?: ConnectionConfig;
|
||||
};
|
||||
import { AddDbEntryParam, APIResponseObject, PostInsertReturn } from "../../../types";
|
||||
/**
|
||||
* Add a db Entry Function
|
||||
*/
|
||||
export default function addDbEntry<T extends {
|
||||
[k: string]: any;
|
||||
} = any, K extends string = string>({ dbContext, paradigm, dbFullName, tableName, data, batchData, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, forceLocal, debug, dbConfig, }: AddDbEntryParam<T, K>): Promise<APIResponseObject<PostInsertReturn>>;
|
||||
} = any, K extends string = string>({ dbContext, paradigm, dbFullName, tableName, data, batchData, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, forceLocal, debug, dbConfig, onDuplicate, }: AddDbEntryParam<T, K>): Promise<APIResponseObject<PostInsertReturn>>;
|
||||
|
||||
+15
-3
@@ -25,7 +25,7 @@ const grab_parsed_value_1 = __importDefault(require("./grab-parsed-value"));
|
||||
* Add a db Entry Function
|
||||
*/
|
||||
function addDbEntry(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, paradigm, dbFullName, tableName, data, batchData, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, forceLocal, debug, dbConfig, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, paradigm, dbFullName, tableName, data, batchData, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, forceLocal, debug, dbConfig, onDuplicate, }) {
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: (0, check_if_is_master_1.default)({ dbContext, dbFullName });
|
||||
@@ -141,8 +141,14 @@ function addDbEntry(_a) {
|
||||
}
|
||||
if (newData) {
|
||||
const { insertKeysArray, insertValuesArray, queryValuesArray } = generateQuery(newData);
|
||||
const query = `INSERT INTO ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${insertKeysArray.join(",")}) VALUES (${grabQueryValuesString(insertValuesArray)})`;
|
||||
let query = `INSERT INTO ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${insertKeysArray.join(",")}) VALUES (${grabQueryValuesString(insertValuesArray)})`;
|
||||
const finalQueryValues = grabFinalQueryValuesArr(queryValuesArray);
|
||||
if (onDuplicate) {
|
||||
query += ` ON DUPLICATE KEY ${onDuplicate.sql}`;
|
||||
if (onDuplicate.values) {
|
||||
finalQueryValues.push(...onDuplicate.values);
|
||||
}
|
||||
}
|
||||
const newInsert = yield (0, conn_db_handler_1.default)({
|
||||
query,
|
||||
values: finalQueryValues,
|
||||
@@ -171,10 +177,16 @@ function addDbEntry(_a) {
|
||||
batchInsertValuesArray.push(insertValuesArray);
|
||||
batchQueryValuesArray.push(queryValuesArray);
|
||||
}
|
||||
const query = `INSERT INTO ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${batchInsertKeysArray === null || batchInsertKeysArray === void 0 ? void 0 : batchInsertKeysArray.join(",")}) VALUES ${batchInsertValuesArray
|
||||
let query = `INSERT INTO ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${batchInsertKeysArray === null || batchInsertKeysArray === void 0 ? void 0 : batchInsertKeysArray.join(",")}) VALUES ${batchInsertValuesArray
|
||||
.map((vl) => `(${grabQueryValuesString(vl)})`)
|
||||
.join(",")}`;
|
||||
const finalQueryValues = grabFinalQueryValuesArr(batchQueryValuesArray.flat());
|
||||
if (onDuplicate) {
|
||||
query += ` ON DUPLICATE KEY ${onDuplicate.sql}`;
|
||||
if (onDuplicate.values) {
|
||||
finalQueryValues.push(...onDuplicate.values);
|
||||
}
|
||||
}
|
||||
const newInsert = yield (0, conn_db_handler_1.default)({
|
||||
query,
|
||||
values: finalQueryValues,
|
||||
|
||||
Reference in New Issue
Block a user