Skip to content

Commit

Permalink
Optimize remote-item script (#5899)
Browse files Browse the repository at this point in the history
  • Loading branch information
themrrobert authored May 27, 2024
1 parent f37ca94 commit c5ffb35
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/scripts/remove-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ import { GearSetupTypes } from '../lib/gear/types';

/* PSQL Function that needs to be created */
const extraFunctions = `
CREATE OR REPLACE FUNCTION remove_jsonb_keys(data jsonb, keys text[])
RETURNS jsonb LANGUAGE plpgsql AS $$
declare
key text;
BEGIN
FOREACH key IN ARRAY keys LOOP
data := data - key;
END LOOP;
RETURN data;
END;
$$;
CREATE OR REPLACE FUNCTION array_remove_multiple(original_array anyarray, values_to_remove anyarray)
RETURNS anyarray AS $$
BEGIN
Expand Down Expand Up @@ -49,7 +38,7 @@ FINAL_QUERY += GearSetupTypes.map(gearType =>
.flat()
.join('\n');

const removeFromBankQuery = (column: string) => `"${column}" = remove_jsonb_keys("${column}"::jsonb, ${arrayToRemove})`;
const removeFromBankQuery = (column: string) => `"${column}" = "${column}"::jsonb - ${arrayToRemove}`;
const removeFromArrayQuery = (column: string) =>
`"${column}" = array_remove_multiple("${column}", ${intArrayToRemove})`;

Expand Down

0 comments on commit c5ffb35

Please sign in to comment.