Skip to main content

Delete 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();

Delete Data​

Delete data from a table through the delete() method. It must be used with filters to target the rows to delete.

db.from(tableName).delete(options).filter()
  • tableName: table name
  • options: delete options configuration

Parameter Description​

ParameterTypeRequiredDescription
optionsobjectNoDelete options configuration

options Parameter Description​

ParameterTypeRequiredDescription
countstringNoCounting algorithm, optional values: "exact" - underlying execution of COUNT(*)

Code Examples​

Delete a Single Record​

// Delete the record with id 1 from the articles table
const { error } = await db.from("articles").delete().eq("id", 1);

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

Bulk Delete Records​

// Bulk delete records with id 1, 2, 3 from the articles table
const { error } = await db.from("articles").delete().in("id", [1, 2, 3]);

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

Conditional Delete​

// Delete all articles with status "draft"
const { error } = await db.from("articles").delete().eq("status", "draft");

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

Return Result​

{
data: null,
error: null
}

Warning: The delete() method must be used with Filters to target the rows you want to delete. Ensure that the conditions you provide accurately represent all the records you intend to delete, to avoid accidentally deleting data.

  • Filters - Learn how to use filter conditions