Skip to main content

Update Data

Initialize the SDK

import cloudbase from "@cloudbase/js-sdk";

const app = cloudbase.init({
env: "your-env-id", // Replace with your environment id
});

const db = app.rdb();

Update Data

Update data in a table through the update() method. It must be used with filters to target the rows to update.

db.from(tableName).update(values, options).filter()
  • tableName: table name
  • values: data to update
  • options: update options configuration

Parameter Description

ParameterTypeRequiredDescription
valuesobjectYesValues to update
optionsobjectNoUpdate options

options Parameter Description

ParameterTypeRequiredDescription
countstringNoCounting algorithm for counting updated rows: "exact" - underlying execution of COUNT(*)

Code Examples

Update Data

// Update the record with id 1 in the articles table, changing the title to "New Title"
const { error } = await db
.from("articles")
.update({ title: "New Title" })
.eq("id", 1);

console.log('Update result:', error ? 'Failed' : 'Success');

Bulk Update

// Update all articles with status "draft" to "published"
const { error } = await db
.from("articles")
.update({ status: "published" })
.eq("status", "draft");

console.log('Bulk update result:', error ? 'Failed' : 'Success');

Return Result

{
data: null,
error: null
}

Note: The update() method must be used with Filters to target the rows you want to update.

  • Filters - Learn how to use filter conditions