Db.updateRow
Db.updateRow($table, $colMap, $whereMapOrSql) -> false
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 updated value is an object, it will try to convert it to a string:
- Date:
$date.format('sql')
- Password:
$password.hash()
- Other:
$object.zSqlString()
(usually the same astoString()
)