Update
Update rows with explicit filters and partial patches, with validation and clear safety boundaries.
Update
update() applies a partial patch to rows that match a filter.
Contract
db.users.update(filter: Partial<User>, patch: Partial<User>): Promise<User[]>Input model
filter: row selector ({ id: 1 },{ email: 'a@example.com' })patch: changed fields only ({ isActive: false })
undefined fields are ignored. Kadak only updates provided keys.
Update one row by id
const rows = await db.users.update(
{ id: 1 },
{ isActive: false },
)Update multiple rows intentionally (bulk patch)
const rows = await db.users.update(
{ isActive: true },
{ isActive: false },
)API-safe request flow
const parsed = usersTable.updateValidator().safeParse(req.body)
if (!parsed.success) {
return res.status(400).json(parsed.error.flatten())
}
const rows = await db.users.update({ id: Number(req.params.id) }, parsed.data)
return res.json(rows[0] ?? null)Runtime behavior
- Empty patch is rejected with a
VALIDATION_ERROR. autoUpdatecolumns (for exampleupdatedAt) are injected automatically.- Returns updated rows after execution.
Production guardrails
- Keep filters explicit and reviewable.
- Avoid broad filters unless you are intentionally running a bulk operation.
- Log bulk updates in service layer code for auditability.