Batch Writes
Insert or upsert multiple rows in one request with the JavaScript Relational SDK.
Overview
The relational SDK accepts one row or an array of rows for insert() and upsert(). Use an array to write multiple rows to the same table.
For the complete write examples, see Writing Data Examples.
Before You Begin
Use a relational project with a registered web app and an initialized client. The target table must exist, and DDS Data Grants must permit the intended writes. Supplied values must satisfy the table’s columns and constraints.
Batch Write Behavior
Each online bulk write sends an array to one table in one request. Check error before using data. By default, the SDK returns data: null for an HTTP error response.
Separate SDK calls save their changes independently. A failed call does not undo an earlier successful call.
Upserts can process rows in a different order from the input array.
Insert and Upsert Rows
Pass an array to insert() to submit multiple rows to the same table:
const { data, error } = await client
.from("todos")
.insert([
{ title: "Plan release", completed: false },
{ title: "Publish release notes", completed: false },
])
.select("id,title");
if (error) {
throw error;
}
Pass an array to upsert() when you need conflict handling. Use the table’s unique or primary-key column in onConflict. See Bulk Inserts and Upserts.
Updating Individual Columns
Use update(values) to send replacement values for selected columns, and chain a filter to restrict affected rows:
const { data, error } = await client
.from("todos")
.update({ completed: true })
.eq("id", 42);