• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 14390553809

10 Apr 2025 09:21PM UTC coverage: 46.287% (-0.1%) from 46.434%
14390553809

push

github

web-flow
Merge pull request #11631 from hicommonwealth/malik.11391.quest-tweets

1611 of 3846 branches covered (41.89%)

Branch coverage included in aggregate %.

10 of 68 new or added lines in 9 files covered. (14.71%)

5 existing lines in 3 files now uncovered.

2958 of 6025 relevant lines covered (49.1%)

40.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

2.94
/libs/model/src/utils/pgMultiRowUpdate.ts
1
import { composeSequelizeLogger, logger } from '@hicommonwealth/core';
2
import { QueryTypes, Transaction } from 'sequelize';
3
import { config } from '../config';
4
import { models } from '../database';
5

6
const log = logger(import.meta, undefined, config.TWITTER.LOG_LEVEL);
32✔
7

8
type Column = {
9
  setColumn: string;
10
  rows: { newValue: string | number; whenCaseValue: string | number }[];
11
};
12

13
/**
14
 * Warning: column name is not escaped.
15
 */
16
export async function pgMultiRowUpdate(
17
  tableName: string,
18
  columns: [Column, ...Column[]],
19
  caseColumn: string,
20
  transaction?: Transaction,
21
) {
22
  if (columns.length === 0) return false;
×
23

NEW
24
  let hasRows = false;
×
NEW
25
  for (const column of columns) {
×
NEW
26
    if (column.rows.length > 0) {
×
NEW
27
      hasRows = true;
×
NEW
28
      break;
×
29
    }
30
  }
NEW
31
  if (!hasRows) return false;
×
32

33
  let updates = ``;
×
NEW
34
  const replacements: unknown[] = [];
×
35
  for (const { setColumn, rows } of columns) {
×
NEW
36
    if (rows.length === 0) continue;
×
37
    if (updates.length > 0) updates += `, \n`;
×
38
    updates += `${setColumn} = CASE \n${rows
×
NEW
39
      .map(() => `\tWHEN ${caseColumn} = ? THEN ?`)
×
40
      .join('\n\t')}`;
NEW
41
    updates += ` \n\tEND`;
×
NEW
42
    replacements.push(
×
43
      ...rows
NEW
44
        .map(({ whenCaseValue, newValue }) => [whenCaseValue, newValue])
×
45
        .flat(),
46
    );
47

NEW
48
    const caseValues = new Set(
×
NEW
49
      columns.map((c) => c.rows.map((r) => r.whenCaseValue)).flat(),
×
50
    );
NEW
51
    const query = `
×
52
      UPDATE "${tableName}"
53
      SET ${updates}
54
      WHERE ${caseColumn} IN (?);
55
  `;
NEW
56
    replacements.push(Array.from(caseValues));
×
57

NEW
58
    await models.sequelize.query(query, {
×
59
      transaction,
60
      type: QueryTypes.UPDATE,
61
      logging: composeSequelizeLogger(log, config.TWITTER.LOG_LEVEL),
62
      replacements,
63
    });
64
  }
UNCOV
65
  return true;
×
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc