Version: v0.8.1 - Beta.  We welcome contributors & feedback.

Db.updateRow

Db.updateRow($table, $colMap, $whereMapOrSql) -> null

Description

Update one row of a table, if it matches $whereMapOrSql.

$whereMapOrSql can be a Map of column-to-value constraints, or a SQL TypeString.

// Update a user's email address

$newVals = {
    email: 'new@example.com'
    updatedDate: Date.now()
}

Db.updateRow('users', $newVals, { userId: 1234 })

// Runs query:
// UPDATE users SET
//    email = 'new@example.com'
//    updatedDate = '2021-03-23 16:38:11'
// WHERE userId = 1234
// LIMIT 1

// With SQL TypeString
$where = sql'userId = {}'.fill(1234)
Db.updateRows('users', $newVals, $where)

Object Values

If an inserted value is an object, it will try to convert it to a string based on its type.

Type Conversion
Date $date.format('sql')
Password $password.hash()
Other $object.onToSqlString() (default: toString())

See Also