Major version update. Major bugfixes. Security vulnerabilites fixed
This commit is contained in:
Vendored
+19
-21
@@ -1,34 +1,32 @@
|
||||
import DbClient from ".";
|
||||
import dbHandler from "../db-handler";
|
||||
import _ from "lodash";
|
||||
import sqlGenerator from "../../utils/sql-generator";
|
||||
export default async function DbDelete({ table, query, targetId, }) {
|
||||
import { sqlIdent } from "../../utils/sql-safe";
|
||||
export default async function DbDelete({ table, query, targetId, config, }) {
|
||||
let sqlObj = null;
|
||||
try {
|
||||
let finalQuery = query || {};
|
||||
if (targetId) {
|
||||
finalQuery = _.merge(finalQuery, {
|
||||
query: {
|
||||
id: {
|
||||
value: String(targetId),
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
const finalQuery = query || {};
|
||||
sqlObj = sqlGenerator({
|
||||
tableName: table,
|
||||
genObject: finalQuery,
|
||||
genObject: _.pick(finalQuery, ["query", "searchOperator"]),
|
||||
targetId,
|
||||
});
|
||||
const whereClause = sqlObj.string.match(/WHERE .*/)?.[0];
|
||||
const whereClause = sqlObj.where.string;
|
||||
if (whereClause) {
|
||||
let sql = `DELETE FROM ${table} ${whereClause}`;
|
||||
let sql = `DELETE FROM ${sqlIdent(table, "table name")} ${whereClause}`;
|
||||
sqlObj.string = sql;
|
||||
const res = DbClient.run(sql, sqlObj.values);
|
||||
sqlObj.values = sqlObj.where.values;
|
||||
const res = dbHandler({
|
||||
query: sql,
|
||||
values: sqlObj.values,
|
||||
config,
|
||||
});
|
||||
if (!res.success) {
|
||||
return { ...res, debug: { sqlObj } };
|
||||
}
|
||||
return {
|
||||
success: Boolean(res.changes),
|
||||
postInsertReturn: {
|
||||
affectedRows: res.changes,
|
||||
insertId: Number(res.lastInsertRowid),
|
||||
},
|
||||
success: Boolean(res.postInsertReturn?.affectedRows),
|
||||
postInsertReturn: res.postInsertReturn,
|
||||
debug: {
|
||||
sqlObj,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user