Updates
This commit is contained in:
@@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user