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

hicommonwealth / commonwealth / 14520831983

17 Apr 2025 04:58PM UTC coverage: 46.287% (+0.01%) from 46.275%
14520831983

Pull #11858

github

web-flow
Merge ca5f7f5f0 into ae20f116a
Pull Request #11858: basic privy auth via hooks.

1622 of 3866 branches covered (41.96%)

Branch coverage included in aggregate %.

2978 of 6072 relevant lines covered (49.04%)

39.55 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

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

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

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