layout | title |
---|---|
default |
Update Queries |
It is recommended to always include a WHERE
statement:
$query = $factory
->update('places', [
'address' => '555 Money Ave'
])
->where(field('name')->eq('work'))
->compile();
$query->sql(); // UPDATE "places" SET "address" = ? WHERE "name" = ?
$query->params(); // ['555 Money Ave', 'work']
When using the Postgres engine RETURNING
can be added:
$query = $factory
->update('users', [
'is_active' => false,
])
->where(field('login_at')->lt('2018-01-01'))
->returning('id')
->compile();
$query->sql(); // UPDATE "users" SET "is_active" = false WHERE "login_at" < ? RETURNING "id"
$query->params(); // ['2018-01-01']