Skip to content

Commit

Permalink
Allow db.all as value of noNullUpdateColumns (addresses #174)
Browse files Browse the repository at this point in the history
  • Loading branch information
jawj committed Jun 21, 2024
1 parent 74e7ad7 commit 122d5c3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/db/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ interface UpsertOptions<
> extends ReturningOptionsForTable<T, C, E> {
updateValues?: UpdatableForTable<T>;
updateColumns?: UC;
noNullUpdateColumns?: ColumnForTable<T> | ColumnForTable<T>[];
noNullUpdateColumns?: ColumnForTable<T> | ColumnForTable<T>[] | typeof all;
reportAction?: RA;
}

Expand Down Expand Up @@ -235,7 +235,7 @@ export const upsert: UpsertSignatures = function (
if (typeof conflictTarget === 'string') conflictTarget = [conflictTarget]; // now either Column[] or Constraint

let noNullUpdateColumns = options?.noNullUpdateColumns ?? [];
if (!Array.isArray(noNullUpdateColumns)) noNullUpdateColumns = [noNullUpdateColumns];
if (noNullUpdateColumns !== all && !Array.isArray(noNullUpdateColumns)) noNullUpdateColumns = [noNullUpdateColumns];

let specifiedUpdateColumns = options?.updateColumns;
if (specifiedUpdateColumns && !Array.isArray(specifiedUpdateColumns)) specifiedUpdateColumns = [specifiedUpdateColumns];
Expand All @@ -256,7 +256,7 @@ export const upsert: UpsertSignatures = function (
updateColsSQL = mapWithSeparator(updateColumns, sql`, `, c => c),
updateValuesSQL = mapWithSeparator(updateColumns, sql`, `, c =>
updateValues[c] !== undefined ? updateValues[c] :
noNullUpdateColumns.includes(c) ? sql`CASE WHEN EXCLUDED.${c} IS NULL THEN ${table}.${c} ELSE EXCLUDED.${c} END` :
(noNullUpdateColumns === all || noNullUpdateColumns.includes(c)) ? sql`CASE WHEN EXCLUDED.${c} IS NULL THEN ${table}.${c} ELSE EXCLUDED.${c} END` :
sql`EXCLUDED.${c}`),
returningSQL = SQLForColumnsOfTable(options?.returning, table),
extrasSQL = SQLForExtras(options?.extras),
Expand Down

0 comments on commit 122d5c3

Please sign in to comment.