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

Db.updateRows

Db.updateRows($table, $colMap, $where) -> false

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 updated value is an object, it will try to convert it to a string:

See Also