MCPcopy Create free account
hub / github.com/DeepNotesApp/DeepNotes / patchMultiple

Function patchMultiple

packages/@stdlib/db/src/index.ts:3–40  ·  view source on GitHub ↗
(
  table: string,
  columns: string[],
  types: string[],
  values: any[][],
  where: string,
  set: string,
  params?: { trx: any },
)

Source from the content-addressed store, hash-verified

1import { Model } from 'objection';
2
3export async function patchMultiple(
4 table: string,
5 columns: string[],
6 types: string[],
7 values: any[][],
8 where: string,
9 set: string,
10 params?: { trx: any },
11) {
12 if (values.length === 0) {
13 return;
14 }
15
16 let query = Model.knex().raw(
17 `
18 UPDATE
19 ${table}
20 SET
21 ${set}
22 FROM (
23 VALUES
24 ${values
25 .map((row) => `(${row.map((_, i) => `?::${types[i]}`).join(', ')})`)
26 .join(', ')}
27 ) AS values (${columns.join(', ')})
28 WHERE
29 ${where}
30 `,
31
32 [...values.flat()],
33 );
34
35 if (params?.trx) {
36 query = query.transacting(params.trx);
37 }
38
39 return await query;
40}

Callers 2

moveStep2Function · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected