Skip to main content

updateMany()

Updates all rows matching the specified conditions to the given values.

Available Keys

KeyDescriptionOptionalNotes
whereSpecifies update conditionsOptionalTargets all rows if omitted
dataData to updateRequired
limitMaximum number of records to updateOptionalNegative values cause an error

Example Sheet

Example Sheet

Description

Suppose you want to perform the following operation on the above example:

  • age => Change 20 to 21

The code would be:

const gassma = new Gassma.GassmaClient();

// gassma.{{TARGET_SHEET_NAME}}.updateMany
const result = gassma.sheet1.updateMany({
where: {
age: 20,
},
data: {
age: 21,
},
});

The return value has the following format:

{
count: 1;
}

The number of updated rows is returned.

The where specification follows findMany().

limit

You can specify the maximum number of records to update:

// Update at most 2 records
const result = gassma.sheet1.updateMany({
where: {
pref: "Tokyo",
},
data: {
age: 99,
},
limit: 2,
});

Specifying limit: 0 results in 0 updates (nothing is updated).

caution

Specifying a negative value for limit throws GassmaLimitNegativeError.

Atomic Number Operations

By specifying increment / decrement / multiply / divide in data, you can perform operations on the current value:

// Increment everyone's age by 1
const result = gassma.sheet1.updateMany({
data: {
age: { increment: 1 },
},
});
OperationBehaviorExample
incrementAddition{ increment: 5 } → current value + 5
decrementSubtraction{ decrement: 3 } → current value - 3
multiplyMultiplication{ multiply: 2 } → current value × 2
divideDivision{ divide: 4 } → current value ÷ 4

If the current value is not a number, 0 is used as the base for calculations. For details, see update().