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;
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 {};

View File

@ -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 || []));
}

View File

@ -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;

View File

@ -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,

View File

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

View File

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

View File

@ -24,6 +24,7 @@ export default async function dsqlCrud<
sanitize,
targetField,
targetId,
targetIds,
dbFullName,
deleteData,
batchData,
@ -100,7 +101,15 @@ export default async function dsqlCrud<
case "delete":
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({
whereClauseObject,
tableName: table,

View File

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