This commit is contained in:
Benjamin Toby 2025-12-13 16:33:58 +01:00
parent c88fb13375
commit 14ea760373
4 changed files with 69 additions and 8 deletions

View File

@ -3,4 +3,4 @@ export default function <T extends {
[key: string]: any;
} = {
[key: string]: any;
}, K extends string = string>({ table, query, count, countOnly, dbFullName, tableSchema, dbConfig, }: Omit<DsqlCrudParam<T, K>, "action" | "data" | "sanitize">): Promise<APIResponseObject>;
}, K extends string = string>({ table, query, count, countOnly, dbFullName, tableSchema, dbConfig, targetId, targetField, targetValue, }: Omit<DsqlCrudParam<T, K>, "action" | "data" | "sanitize">): Promise<APIResponseObject>;

View File

@ -18,13 +18,34 @@ const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-ge
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
const check_array_depth_1 = __importDefault(require("../check-array-depth"));
const parseDbResults_1 = __importDefault(require("../../functions/backend/parseDbResults"));
const lodash_1 = __importDefault(require("lodash"));
function default_1(_a) {
return __awaiter(this, arguments, void 0, function* ({ table, query, count, countOnly, dbFullName, tableSchema, dbConfig, }) {
return __awaiter(this, arguments, void 0, function* ({ table, query, count, countOnly, dbFullName, tableSchema, dbConfig, targetId, targetField, targetValue, }) {
var _b, _c, _d, _e;
let queryObject;
let crudQueryObj = lodash_1.default.cloneDeep(query);
if (targetId) {
crudQueryObj = lodash_1.default.merge(crudQueryObj || {}, {
query: {
id: {
value: String(targetId),
},
},
});
}
if (targetField &&
(typeof targetValue == "string" || typeof targetValue == "number")) {
crudQueryObj = lodash_1.default.merge(crudQueryObj || {}, {
query: {
[targetField]: {
value: String(targetValue),
},
},
});
}
queryObject = (0, sql_generator_1.default)({
tableName: table,
genObject: query,
genObject: crudQueryObj,
dbFullName,
});
let connQueries = [
@ -36,7 +57,7 @@ function default_1(_a) {
const countQueryObject = count || countOnly
? (0, sql_generator_1.default)({
tableName: table,
genObject: query,
genObject: crudQueryObj,
count: true,
dbFullName,
})

View File

@ -1,9 +1,15 @@
import { format } from "sql-formatter";
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
import { APIResponseObject, DsqlCrudParam } from "../../types";
import {
APIResponseObject,
DsqlCrudParam,
DsqlCrudQueryObject,
ServerQueryQueryObject,
} from "../../types";
import connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler";
import checkArrayDepth from "../check-array-depth";
import parseDbResults from "../../functions/backend/parseDbResults";
import _ from "lodash";
export default async function <
T extends { [key: string]: any } = { [key: string]: any },
@ -16,15 +22,49 @@ export default async function <
dbFullName,
tableSchema,
dbConfig,
targetId,
targetField,
targetValue,
}: Omit<
DsqlCrudParam<T, K>,
"action" | "data" | "sanitize"
>): Promise<APIResponseObject> {
let queryObject: ReturnType<Awaited<typeof sqlGenerator>> | undefined;
let crudQueryObj = _.cloneDeep(query);
if (targetId) {
crudQueryObj = _.merge<
DsqlCrudQueryObject<T, K>,
DsqlCrudQueryObject<T, K>
>(crudQueryObj || {}, {
query: {
id: {
value: String(targetId),
},
} as ServerQueryQueryObject<T, K>,
});
}
if (
targetField &&
(typeof targetValue == "string" || typeof targetValue == "number")
) {
crudQueryObj = _.merge<
DsqlCrudQueryObject<T, K>,
DsqlCrudQueryObject<T, K>
>(crudQueryObj || {}, {
query: {
[targetField]: {
value: String(targetValue),
},
} as ServerQueryQueryObject<T, K>,
});
}
queryObject = sqlGenerator({
tableName: table,
genObject: query,
genObject: crudQueryObj,
dbFullName,
});
@ -39,7 +79,7 @@ export default async function <
count || countOnly
? sqlGenerator({
tableName: table,
genObject: query,
genObject: crudQueryObj,
count: true,
dbFullName,
})

View File

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