Updates
This commit is contained in:
+1
-1
@@ -3,4 +3,4 @@ export default function <T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}>({ table, query, count, countOnly, dbFullName, }: Omit<DsqlCrudParam<T>, "action" | "data" | "sanitize">): Promise<APIResponseObject>;
|
||||
}>({ table, query, count, countOnly, dbFullName, tableSchema, }: Omit<DsqlCrudParam<T>, "action" | "data" | "sanitize">): Promise<APIResponseObject>;
|
||||
|
||||
+18
-4
@@ -15,8 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
|
||||
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"));
|
||||
function default_1(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ table, query, count, countOnly, dbFullName, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ table, query, count, countOnly, dbFullName, tableSchema, }) {
|
||||
var _b, _c, _d, _e;
|
||||
let queryObject;
|
||||
queryObject = (0, sql_generator_1.default)({
|
||||
@@ -53,12 +55,24 @@ function default_1(_a) {
|
||||
];
|
||||
}
|
||||
const res = yield (0, conn_db_handler_1.default)(undefined, connQueries);
|
||||
const parsedRes = (0, check_array_depth_1.default)(res, 2)
|
||||
? (0, parseDbResults_1.default)({ unparsedResults: res[0], tableSchema })
|
||||
: res[0];
|
||||
const parsedBatchRes = (0, check_array_depth_1.default)(res, 3)
|
||||
? res.map((_r) => {
|
||||
return (0, parseDbResults_1.default)({ unparsedResults: _r[0], tableSchema });
|
||||
})
|
||||
: res;
|
||||
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
return {
|
||||
success: isSuccess,
|
||||
payload: isSuccess ? (countOnly ? null : res[0]) : null,
|
||||
batchPayload: isSuccess ? (countOnly ? null : res) : null,
|
||||
error: isSuccess ? undefined : res === null || res === void 0 ? void 0 : res.error,
|
||||
payload: isSuccess ? (countOnly ? null : parsedRes) : null,
|
||||
batchPayload: isSuccess ? (countOnly ? null : parsedBatchRes) : null,
|
||||
error: isSuccess
|
||||
? undefined
|
||||
: typeof res == "object" && !Array.isArray(res)
|
||||
? res === null || res === void 0 ? void 0 : res.error
|
||||
: undefined,
|
||||
errors: res === null || res === void 0 ? void 0 : res.errors,
|
||||
queryObject: {
|
||||
sql: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
||||
|
||||
+3
-1
@@ -20,7 +20,7 @@ const addDbEntry_1 = __importDefault(require("../../functions/backend/db/addDbEn
|
||||
const updateDbEntry_1 = __importDefault(require("../../functions/backend/db/updateDbEntry"));
|
||||
function dsqlCrud(params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { action, data, table, targetValue, sanitize, targetField, targetId, dbFullName, deleteData, batchData, deleteKeyValues, debug, } = params;
|
||||
const { action, data, table, targetValue, sanitize, targetField, targetId, dbFullName, deleteData, batchData, deleteKeyValues, debug, tableSchema, } = params;
|
||||
const finalData = (sanitize ? sanitize({ data }) : data);
|
||||
const finalBatchData = (sanitize ? sanitize({ batchData }) : batchData);
|
||||
switch (action) {
|
||||
@@ -35,6 +35,7 @@ function dsqlCrud(params) {
|
||||
tableName: table,
|
||||
dbFullName,
|
||||
debug,
|
||||
tableSchema,
|
||||
});
|
||||
return INSERT_RESULT;
|
||||
case "update":
|
||||
@@ -46,6 +47,7 @@ function dsqlCrud(params) {
|
||||
identifierColumnName: (targetField || "id"),
|
||||
identifierValue: String(targetValue || targetId),
|
||||
debug,
|
||||
tableSchema,
|
||||
});
|
||||
return UPDATE_RESULT;
|
||||
case "delete":
|
||||
|
||||
Reference in New Issue
Block a user