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

hicommonwealth / commonwealth / 14516079906

17 Apr 2025 12:51PM UTC coverage: 46.275%. Remained the same
14516079906

push

github

web-flow
Merge pull request #11873 from hicommonwealth/tim/fix-twitter-worker

1621 of 3864 branches covered (41.95%)

Branch coverage included in aggregate %.

0 of 9 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

2976 of 6070 relevant lines covered (49.03%)

39.56 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

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

33
  let updates = ``;
×
34
  const replacements: unknown[] = [];
×
35
  for (const { setColumn, rows } of columns) {
×
36
    if (rows.length === 0) continue;
×
37
    if (updates.length > 0) updates += `, \n`;
×
38

NEW
39
    updates += `${setColumn} = CASE `;
×
NEW
40
    for (const { whenCaseValue, newValue } of rows) {
×
NEW
41
      updates += `\n\tWHEN ${caseColumn} = ? THEN ?`;
×
NEW
42
      replacements.push(whenCaseValue, newValue);
×
43
    }
44
    updates += ` \n\tEND`;
×
45
  }
46

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

NEW
57
  await models.sequelize.query(query, {
×
58
    transaction,
59
    type: QueryTypes.UPDATE,
60
    logging: composeSequelizeLogger(log, config.TWITTER.LOG_LEVEL),
61
    replacements,
62
  });
UNCOV
63
  return true;
×
64
}
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