update
The update builder provides a type-safe way to modify existing items in DynamoDB using UpdateItem.
import { db } from "./db";import { users } from "./schema";import { eq } from "@aurios/mizzle";
await db.update(users).set({ name: "Jane Doe" }).where(eq(users.id, "123")).execute();Methods
Section titled “Methods”update(entity)
Section titled “update(entity)”Initializes the update builder for a specific entity.
- Arguments:
entity: A Mizzle entity definition.
- Returns:
UpdateBuilder
set(values)
Section titled “set(values)”Sets the values for specific fields. Corresponds to the SET action in DynamoDB update expressions.
- Arguments:
values: A partial object of the entity’s fields.
- Returns:
this
add(values)
Section titled “add(values)”Adds a value to a numeric field or elements to a set. Corresponds to the ADD action.
- Arguments:
values: An object mapping field names to values.
- Returns:
this
remove(...fields)
Section titled “remove(...fields)”Removes specific fields from the item. Corresponds to the REMOVE action.
- Arguments:
fields: A list of field names to remove.
- Returns:
this
delete(values)
Section titled “delete(values)”Removes elements from a set. Corresponds to the DELETE action.
- Arguments:
values: An object mapping set fields to the elements to remove.
- Returns:
this
where(expression)
Section titled “where(expression)”Specifies the item(s) to update. For UpdateItem, this must resolve to the full primary key (PK and SK).
- Arguments:
expression: A Mizzle expression that resolves to the entity’s keys.
- Returns:
this
returning(type)
Section titled “returning(type)”Specifies what the operation should return.
- Arguments:
type:"NONE" | "ALL_OLD" | "UPDATED_OLD" | "ALL_NEW" | "UPDATED_NEW"
- Returns:
this
execute()
Section titled “execute()”Executes the UpdateItem operation.
- Returns:
Promise<T>