Updates
This commit is contained in:
@@ -11,6 +11,7 @@ type Param<T extends {
|
||||
identifierValue?: string | number;
|
||||
forceLocal?: boolean;
|
||||
whereClauseObject?: DsqlCrudParamWhereClause;
|
||||
targetIds?: (string | number)[];
|
||||
};
|
||||
/**
|
||||
* # Delete DB Entry Function
|
||||
@@ -18,5 +19,5 @@ type Param<T extends {
|
||||
*/
|
||||
export default function deleteDbEntry<T extends {
|
||||
[k: string]: any;
|
||||
} = any, K extends string = string>({ dbContext, dbFullName, tableName, identifierColumnName, identifierValue, forceLocal, whereClauseObject, }: Param<T, K>): Promise<APIResponseObject<PostInsertReturn>>;
|
||||
} = any, K extends string = string>({ dbContext, dbFullName, tableName, identifierColumnName, identifierValue, forceLocal, whereClauseObject, targetIds, }: Param<T, K>): Promise<APIResponseObject<PostInsertReturn>>;
|
||||
export {};
|
||||
|
||||
@@ -21,7 +21,7 @@ const conn_db_handler_1 = __importDefault(require("../../../utils/db/conn-db-han
|
||||
* @description
|
||||
*/
|
||||
function deleteDbEntry(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, dbFullName, tableName, identifierColumnName, identifierValue, forceLocal, whereClauseObject, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, dbFullName, tableName, identifierColumnName, identifierValue, forceLocal, whereClauseObject, targetIds, }) {
|
||||
try {
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
@@ -33,7 +33,11 @@ function deleteDbEntry(_a) {
|
||||
*/
|
||||
let query = `DELETE FROM ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\``;
|
||||
let values = [];
|
||||
if (whereClauseObject) {
|
||||
if (targetIds) {
|
||||
query += ` WHERE id IN (${targetIds.map((id) => "?").join(",")})`;
|
||||
values = targetIds;
|
||||
}
|
||||
else if (whereClauseObject) {
|
||||
query += ` ${whereClauseObject.clause}`;
|
||||
values.push(...(whereClauseObject.params || []));
|
||||
}
|
||||
|
||||
Vendored
+2
-1
@@ -1326,6 +1326,7 @@ export type DsqlCrudParam<T extends {
|
||||
deleteKeyValues?: SQLDeleteData[];
|
||||
deleteKeyValuesOperator?: "AND" | "OR";
|
||||
targetId?: string | number;
|
||||
targetIds?: (string | number)[];
|
||||
targetValue?: string | number;
|
||||
targetField?: keyof T;
|
||||
query?: DsqlCrudQueryObject<T, K>;
|
||||
@@ -2276,7 +2277,7 @@ export type APIPathsQuery<T extends {
|
||||
[k: string]: any;
|
||||
}> = {
|
||||
searchQuery?: DsqlCrudQueryObject<T>;
|
||||
crudParams?: Pick<DsqlCrudParam<T>, "count" | "countOnly" | "targetId" | "targetField" | "targetValue" | "tableSchema" | "onDuplicate">;
|
||||
crudParams?: Pick<DsqlCrudParam<T>, "count" | "countOnly" | "targetId" | "targetIds" | "targetField" | "targetValue" | "tableSchema" | "onDuplicate">;
|
||||
};
|
||||
export type APIPathsParamsGetMiddleware<T extends {
|
||||
[k: string]: any;
|
||||
|
||||
+10
-2
@@ -24,7 +24,7 @@ const deleteDbEntry_1 = __importDefault(require("../../functions/backend/db/dele
|
||||
function dsqlCrud(params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a;
|
||||
const { action, data, table, targetValue, sanitize, targetField, targetId, dbFullName, deleteData, batchData, deleteKeyValues, debug, tableSchema, deleteKeyValuesOperator, dbConfig, query, onDuplicate, } = params;
|
||||
const { action, data, table, targetValue, sanitize, targetField, targetId, targetIds, dbFullName, deleteData, batchData, deleteKeyValues, debug, tableSchema, deleteKeyValuesOperator, dbConfig, query, onDuplicate, } = params;
|
||||
const finalData = (sanitize ? sanitize({ data }) : data);
|
||||
const finalBatchData = (sanitize ? sanitize({ batchData }) : batchData);
|
||||
const queryObject = query
|
||||
@@ -74,7 +74,15 @@ function dsqlCrud(params) {
|
||||
return UPDATE_RESULT;
|
||||
case "delete":
|
||||
let res;
|
||||
if (whereClauseObject) {
|
||||
if (targetIds) {
|
||||
const DELETE_RES = yield (0, deleteDbEntry_1.default)({
|
||||
tableName: table,
|
||||
dbFullName,
|
||||
targetIds,
|
||||
});
|
||||
return DELETE_RES;
|
||||
}
|
||||
else if (whereClauseObject) {
|
||||
const DELETE_RES = yield (0, deleteDbEntry_1.default)({
|
||||
whereClauseObject,
|
||||
tableName: table,
|
||||
|
||||
Reference in New Issue
Block a user