Db.updateRows
Db.updateRows($table, $colMap, $where) -> null
Description
Update zero or more rows of a table that matches $whereMapOrSql
.
$whereMapOrSql
can be a Map of column-to-value constraints, or a SQL TypeString.
// Mark all of a user's messages as 'read' $newVals = { isRead: 1, readDate: Date.now() } Db.updateRows('messages', $newVals, { toUserId: 1234 }) // Runs query: // UPDATE messages // SET isRead = 1, readDate = '2021-03-23 16:38:11' // WHERE toUserId = 1234 // Operator in key $oneYearAgo = Date.create('1 year ago') Db.updateRows('posts', { isArchive: 1 }, { 'postDate <': $oneYearAgo }) // With SQL TypeString $where = sql'postDate < {}'.fill($oneYearAgo) Db.updateRows('posts', { isArchive: 1 }, $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() ) |