Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 22x 22x 22x 22x 22x 22x 22x 6x 1x 5x 5x 5x 5x 1x 4x 22x | import assignObject from './assign-object.js'
import fallback from './fallback.js'
import limitedHintsIdentifier from './limited-hints-identifier.js'
import logicalTrue from './logical-true.js'
import tsql from './template.js'
import type { TableHintLimited } from './table-hint-limited.js'
import type S from './sanitised.js'
import type Sid from './sanitised-identifier.js'
import whereOf from './where.js'
/** @returns UPDATE DML. */
export const update =
(
table: Sid | string,
where: S | Record<string, unknown>,
object: Record<string, unknown>,
{ hints = [ 'repeatableread' ] }: {
hints?: TableHintLimited[]
} = {}
): undefined | S => {
if (Object.keys(object).length === 0) {
return
}
const table_ = limitedHintsIdentifier(table, hints)
const where_ = fallback(where, whereOf) ?? logicalTrue
const object_ = assignObject(object)
if (typeof object_ === 'undefined') {
return
}
return tsql`
update ${table_}
set
${object_}
where ${where_}
`
}
export default update
|