Updates
This commit is contained in:
parent
c88fb13375
commit
14ea760373
@ -3,4 +3,4 @@ export default function <T extends {
|
|||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[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>;
|
||||||
|
|||||||
@ -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 conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
||||||
const check_array_depth_1 = __importDefault(require("../check-array-depth"));
|
const check_array_depth_1 = __importDefault(require("../check-array-depth"));
|
||||||
const parseDbResults_1 = __importDefault(require("../../functions/backend/parseDbResults"));
|
const parseDbResults_1 = __importDefault(require("../../functions/backend/parseDbResults"));
|
||||||
|
const lodash_1 = __importDefault(require("lodash"));
|
||||||
function default_1(_a) {
|
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;
|
var _b, _c, _d, _e;
|
||||||
let queryObject;
|
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)({
|
queryObject = (0, sql_generator_1.default)({
|
||||||
tableName: table,
|
tableName: table,
|
||||||
genObject: query,
|
genObject: crudQueryObj,
|
||||||
dbFullName,
|
dbFullName,
|
||||||
});
|
});
|
||||||
let connQueries = [
|
let connQueries = [
|
||||||
@ -36,7 +57,7 @@ function default_1(_a) {
|
|||||||
const countQueryObject = count || countOnly
|
const countQueryObject = count || countOnly
|
||||||
? (0, sql_generator_1.default)({
|
? (0, sql_generator_1.default)({
|
||||||
tableName: table,
|
tableName: table,
|
||||||
genObject: query,
|
genObject: crudQueryObj,
|
||||||
count: true,
|
count: true,
|
||||||
dbFullName,
|
dbFullName,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,9 +1,15 @@
|
|||||||
import { format } from "sql-formatter";
|
import { format } from "sql-formatter";
|
||||||
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
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 connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler";
|
||||||
import checkArrayDepth from "../check-array-depth";
|
import checkArrayDepth from "../check-array-depth";
|
||||||
import parseDbResults from "../../functions/backend/parseDbResults";
|
import parseDbResults from "../../functions/backend/parseDbResults";
|
||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
export default async function <
|
export default async function <
|
||||||
T extends { [key: string]: any } = { [key: string]: any },
|
T extends { [key: string]: any } = { [key: string]: any },
|
||||||
@ -16,15 +22,49 @@ export default async function <
|
|||||||
dbFullName,
|
dbFullName,
|
||||||
tableSchema,
|
tableSchema,
|
||||||
dbConfig,
|
dbConfig,
|
||||||
|
targetId,
|
||||||
|
targetField,
|
||||||
|
targetValue,
|
||||||
}: Omit<
|
}: Omit<
|
||||||
DsqlCrudParam<T, K>,
|
DsqlCrudParam<T, K>,
|
||||||
"action" | "data" | "sanitize"
|
"action" | "data" | "sanitize"
|
||||||
>): Promise<APIResponseObject> {
|
>): Promise<APIResponseObject> {
|
||||||
let queryObject: ReturnType<Awaited<typeof sqlGenerator>> | undefined;
|
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({
|
queryObject = sqlGenerator({
|
||||||
tableName: table,
|
tableName: table,
|
||||||
genObject: query,
|
genObject: crudQueryObj,
|
||||||
dbFullName,
|
dbFullName,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -39,7 +79,7 @@ export default async function <
|
|||||||
count || countOnly
|
count || countOnly
|
||||||
? sqlGenerator({
|
? sqlGenerator({
|
||||||
tableName: table,
|
tableName: table,
|
||||||
genObject: query,
|
genObject: crudQueryObj,
|
||||||
count: true,
|
count: true,
|
||||||
dbFullName,
|
dbFullName,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "5.5.3",
|
"version": "5.5.4",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user