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

teableio / teable / 20065394908

09 Dec 2025 01:36PM UTC coverage: 71.858%. First build
20065394908

Pull #2168

github

web-flow
Merge b9dc7a0f8 into 6fd609a47
Pull Request #2168: feat: base node

22892 of 25545 branches covered (89.61%)

1916 of 2478 new or added lines in 35 files covered. (77.32%)

57741 of 80354 relevant lines covered (71.86%)

4259.47 hits per line

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

94.74
/apps/nestjs-backend/src/features/base-node/helper.ts
1
import type { Knex } from 'knex';
5✔
2
import { snakeCase } from 'lodash';
3

4
export const buildBatchUpdateSql = (
5✔
5
  knex: Knex,
2,084✔
6
  data: { id: string; values: { [key: string]: unknown } }[]
2,084✔
7
): string | null => {
8
  if (data.length === 0) {
2,084✔
9
    return null;
1✔
10
  }
1✔
11

12
  const caseStatements: Record<string, { when: string; then: unknown }[]> = {};
2,083✔
13
  for (const { id, values } of data) {
2,084✔
14
    for (const [key, value] of Object.entries(values)) {
12,072✔
15
      if (!caseStatements[key]) {
24,136✔
16
        caseStatements[key] = [];
4,162✔
17
      }
4,162✔
18
      caseStatements[key].push({ when: id, then: value });
24,136✔
19
    }
24,136✔
20
  }
12,072✔
21

22
  const updatePayload: Record<string, Knex.Raw> = {};
2,083✔
23
  for (const [key, statements] of Object.entries(caseStatements)) {
2,084✔
24
    if (statements.length === 0) {
4,162!
NEW
25
      continue;
×
NEW
26
    }
×
27
    const column = snakeCase(key);
4,162✔
28
    const whenClauses: string[] = [];
4,162✔
29
    const caseBindings: unknown[] = [];
4,162✔
30
    for (const { when, then } of statements) {
4,162✔
31
      whenClauses.push('WHEN ?? = ? THEN ?');
24,136✔
32
      caseBindings.push('id', when, then);
24,136✔
33
    }
24,136✔
34
    const caseExpression = `CASE ${whenClauses.join(' ')} ELSE ?? END`;
4,162✔
35
    const rawExpression = knex.raw(caseExpression, [...caseBindings, column]);
4,162✔
36
    updatePayload[column] = rawExpression;
4,162✔
37
  }
4,162✔
38

39
  if (Object.keys(updatePayload).length === 0) {
2,084!
40
    return null;
1✔
41
  }
1✔
42

43
  const idsToUpdate = data.map((item) => item.id);
2,082✔
44
  return knex('base_node').update(updatePayload).whereIn('id', idsToUpdate).toQuery();
2,082✔
45
};
2,082✔
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

© 2025 Coveralls, Inc