This commit is contained in:
Benjamin Toby 2026-01-04 12:41:19 +01:00
parent def2f2f057
commit 18e29fa413
8 changed files with 39 additions and 9 deletions

View File

@ -11,6 +11,7 @@ type Param<T extends {
identifierValue?: string | number; identifierValue?: string | number;
forceLocal?: boolean; forceLocal?: boolean;
whereClauseObject?: DsqlCrudParamWhereClause; whereClauseObject?: DsqlCrudParamWhereClause;
targetIds?: (string | number)[];
}; };
/** /**
* # Delete DB Entry Function * # Delete DB Entry Function
@ -18,5 +19,5 @@ type Param<T extends {
*/ */
export default function deleteDbEntry<T extends { export default function deleteDbEntry<T extends {
[k: string]: any; [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 {}; export {};

View File

@ -21,7 +21,7 @@ const conn_db_handler_1 = __importDefault(require("../../../utils/db/conn-db-han
* @description * @description
*/ */
function deleteDbEntry(_a) { 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 { try {
const isMaster = forceLocal const isMaster = forceLocal
? true ? true
@ -33,7 +33,11 @@ function deleteDbEntry(_a) {
*/ */
let query = `DELETE FROM ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\``; let query = `DELETE FROM ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\``;
let values = []; let values = [];
if (whereClauseObject) { if (targetIds) {
query += ` WHERE id IN (${targetIds.map((id) => "?").join(",")})`;
values = targetIds;
}
else if (whereClauseObject) {
query += ` ${whereClauseObject.clause}`; query += ` ${whereClauseObject.clause}`;
values.push(...(whereClauseObject.params || [])); values.push(...(whereClauseObject.params || []));
} }

View File

@ -1326,6 +1326,7 @@ export type DsqlCrudParam<T extends {
deleteKeyValues?: SQLDeleteData[]; deleteKeyValues?: SQLDeleteData[];
deleteKeyValuesOperator?: "AND" | "OR"; deleteKeyValuesOperator?: "AND" | "OR";
targetId?: string | number; targetId?: string | number;
targetIds?: (string | number)[];
targetValue?: string | number; targetValue?: string | number;
targetField?: keyof T; targetField?: keyof T;
query?: DsqlCrudQueryObject<T, K>; query?: DsqlCrudQueryObject<T, K>;
@ -2276,7 +2277,7 @@ export type APIPathsQuery<T extends {
[k: string]: any; [k: string]: any;
}> = { }> = {
searchQuery?: DsqlCrudQueryObject<T>; 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 { export type APIPathsParamsGetMiddleware<T extends {
[k: string]: any; [k: string]: any;

View File

@ -24,7 +24,7 @@ const deleteDbEntry_1 = __importDefault(require("../../functions/backend/db/dele
function dsqlCrud(params) { function dsqlCrud(params) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
var _a; 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 finalData = (sanitize ? sanitize({ data }) : data);
const finalBatchData = (sanitize ? sanitize({ batchData }) : batchData); const finalBatchData = (sanitize ? sanitize({ batchData }) : batchData);
const queryObject = query const queryObject = query
@ -74,7 +74,15 @@ function dsqlCrud(params) {
return UPDATE_RESULT; return UPDATE_RESULT;
case "delete": case "delete":
let res; 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)({ const DELETE_RES = yield (0, deleteDbEntry_1.default)({
whereClauseObject, whereClauseObject,
tableName: table, tableName: table,

View File

@ -18,6 +18,7 @@ type Param<T extends { [k: string]: any } = any, K extends string = string> = {
identifierValue?: string | number; identifierValue?: string | number;
forceLocal?: boolean; forceLocal?: boolean;
whereClauseObject?: DsqlCrudParamWhereClause; whereClauseObject?: DsqlCrudParamWhereClause;
targetIds?: (string | number)[];
}; };
/** /**
@ -35,6 +36,7 @@ export default async function deleteDbEntry<
identifierValue, identifierValue,
forceLocal, forceLocal,
whereClauseObject, whereClauseObject,
targetIds,
}: Param<T, K>): Promise<APIResponseObject<PostInsertReturn>> { }: Param<T, K>): Promise<APIResponseObject<PostInsertReturn>> {
try { try {
const isMaster = forceLocal const isMaster = forceLocal
@ -52,7 +54,10 @@ export default async function deleteDbEntry<
let values: any[] = []; let values: any[] = [];
if (whereClauseObject) { if (targetIds) {
query += ` WHERE id IN (${targetIds.map((id) => "?").join(",")})`;
values = targetIds;
} else if (whereClauseObject) {
query += ` ${whereClauseObject.clause}`; query += ` ${whereClauseObject.clause}`;
values.push(...(whereClauseObject.params || [])); values.push(...(whereClauseObject.params || []));
} else if (identifierColumnName && identifierValue) { } else if (identifierColumnName && identifierValue) {

View File

@ -1559,6 +1559,7 @@ export type DsqlCrudParam<
deleteKeyValues?: SQLDeleteData[]; deleteKeyValues?: SQLDeleteData[];
deleteKeyValuesOperator?: "AND" | "OR"; deleteKeyValuesOperator?: "AND" | "OR";
targetId?: string | number; targetId?: string | number;
targetIds?: (string | number)[];
targetValue?: string | number; targetValue?: string | number;
targetField?: keyof T; targetField?: keyof T;
query?: DsqlCrudQueryObject<T, K>; query?: DsqlCrudQueryObject<T, K>;
@ -2945,6 +2946,7 @@ export type APIPathsQuery<
| "count" | "count"
| "countOnly" | "countOnly"
| "targetId" | "targetId"
| "targetIds"
| "targetField" | "targetField"
| "targetValue" | "targetValue"
| "tableSchema" | "tableSchema"

View File

@ -24,6 +24,7 @@ export default async function dsqlCrud<
sanitize, sanitize,
targetField, targetField,
targetId, targetId,
targetIds,
dbFullName, dbFullName,
deleteData, deleteData,
batchData, batchData,
@ -100,7 +101,15 @@ export default async function dsqlCrud<
case "delete": case "delete":
let res: PostInsertReturn; let res: PostInsertReturn;
if (whereClauseObject) { if (targetIds) {
const DELETE_RES = await deleteDbEntry({
tableName: table,
dbFullName,
targetIds,
});
return DELETE_RES;
} else if (whereClauseObject) {
const DELETE_RES = await deleteDbEntry({ const DELETE_RES = await deleteDbEntry({
whereClauseObject, whereClauseObject,
tableName: table, tableName: table,

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/datasquirel", "name": "@moduletrace/datasquirel",
"version": "5.7.17", "version": "5.7.18",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {