Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.
HarmonyOS
You can use the delete() method to delete a single object or a group of objects. When deleting data, Cloud DB will delete the corresponding data based on the input object's primary key, without checking whether other attributes of the object are consistent with the stored data. The delete operation is atomic. That is, all objects in the list either are deleted successfully or fail to be deleted.
Objects to be deleted in a batch must belong to the same object type. Otherwise, the delete operation will fail.
When calling the data deletion method, there are two ways to return the result: either by returning a Promise object or by passing a callback object in the parameters. The following example explains the Promise approach in detail.
This feature supports phones and tablets by default. Starting from version 5.1.0(18), support for wearables is added. From version 5.1.1(19), TVs are also supported. From version 6.1.0(23), PCs/2-in-1 devices are supported as well.
You have initialized database access.
Sample code:
When you delete objects, the number of deleted objects will be returned if the deletion succeeds; otherwise, an exception will be thrown.
- // If a book is lost, the librarian needs to delete the book from the **BookInfo** table.
- async delete() {
- try {
- let book = new BookInfo();
- book.id = 3;
- let deleteNum = await databaseZone.delete(book);
- hilog.info(0x0000, 'testTag', `Succeeded in deleting data, result: ${JSON.stringify(deleteNum)}`);
- } catch (err) {
- hilog.error(0x0000, 'testTag', `Failed to delete data, code: ${err.code}, message: ${err.message}`);
- }
- }
Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Quick start
Helps you find desired resources with ease.