MCPcopy Create free account
hub / github.com/NobleMajo/al-sql / updateQuery

Method updateQuery

src/pg.ts:371–394  ·  view source on GitHub ↗
(
        table: SqlTable,
        set: SqlSetValueMap,
        where?: SqlCondition,
        returning?: SqlResultColumnSelector | undefined,
    )

Source from the content-addressed store, hash-verified

369 }
370
371 updateQuery(
372 table: SqlTable,
373 set: SqlSetValueMap,
374 where?: SqlCondition,
375 returning?: SqlResultColumnSelector | undefined,
376 ): ExecutableSqlQuery {
377 let i: [number] = [1]
378 let line = `UPDATE "${table.name}"`
379 line += ` SET ${Object.keys(set).map((k) => k + "=$" + (i[0]++)).join(", ")}`
380 let values: any[] = []
381 if (where && Object.keys(where).length > 0) {
382 const whereData = this.createSqlWhereCondition(table.name, where, i)
383 line += ` WHERE ${whereData[0]}`
384 values = whereData.slice(1)
385 }
386 if (typeof returning != "undefined") {
387 line += ` RETURNING ${this.createSelectQuery(returning)}`
388 }
389 return [
390 line,
391 ...Object.values(set),
392 ...values
393 ]
394 }
395
396 selectQuery(
397 table: SqlTable,

Callers

nothing calls this directly

Calls 2

createSelectQueryMethod · 0.95

Tested by

no test coverage detected