如何从多个Baqend表中删除所有数据?

时间:2022-01-31 03:24:20

I need to delete all rows from multiple tables, programmatically (not in the dashboard). Is there an API for that? I couldn't find it in the documentation.

我需要以编程方式(不在仪表板中)从多个表中删除所有行。那有API吗?我在文档中找不到它。

1 个解决方案

#1


2  

You are right, this is currently not documented. You can however find the REST call in our API Explorer although you don't get the syntactic sugar from the JS SDK. The REST call is a DELETE to /db/{bucket} where bucket is the name of the Table to delete. With the JS SDK this request is wrapped into a message object TruncateBucket, you can use it like this:

你是对的,目前没有记录。但是,您可以在我们的API Explorer中找到REST调用,尽管您没有从JS SDK获得语法糖。 REST调用是对/ db / {bucket}的DELETE,其中bucket是要删除的表的名称。使用JS SDK将此请求包装到消息对象TruncateBucket中,您可以像这样使用它:

    DB.login("userWithAdminRole", "<password>").then(function() {
        return DB.send(new DB.message.TruncateBucket('<table>'));
    }).then(function () {
        console.log('truncated!');
    }).catch(function() {
        console.log('catch truncated!');
    });

Note: If you are calling this code from your frontend you need the admin role (hence the DB.login). If you are calling the code from a backend module (where you always have the node role) you can skip the login.

注意:如果从前端调用此代码,则需要admin角色(因此为DB.login)。如果从后端模块(您始终具有节点角色)调用代码,则可以跳过登录。


You can also try out all REST request in the API Explorer. It looks like this:

您还可以在API Explorer中尝试所有REST请求。它看起来像这样:

如何从多个Baqend表中删除所有数据?

#1


2  

You are right, this is currently not documented. You can however find the REST call in our API Explorer although you don't get the syntactic sugar from the JS SDK. The REST call is a DELETE to /db/{bucket} where bucket is the name of the Table to delete. With the JS SDK this request is wrapped into a message object TruncateBucket, you can use it like this:

你是对的,目前没有记录。但是,您可以在我们的API Explorer中找到REST调用,尽管您没有从JS SDK获得语法糖。 REST调用是对/ db / {bucket}的DELETE,其中bucket是要删除的表的名称。使用JS SDK将此请求包装到消息对象TruncateBucket中,您可以像这样使用它:

    DB.login("userWithAdminRole", "<password>").then(function() {
        return DB.send(new DB.message.TruncateBucket('<table>'));
    }).then(function () {
        console.log('truncated!');
    }).catch(function() {
        console.log('catch truncated!');
    });

Note: If you are calling this code from your frontend you need the admin role (hence the DB.login). If you are calling the code from a backend module (where you always have the node role) you can skip the login.

注意:如果从前端调用此代码,则需要admin角色(因此为DB.login)。如果从后端模块(您始终具有节点角色)调用代码,则可以跳过登录。


You can also try out all REST request in the API Explorer. It looks like this:

您还可以在API Explorer中尝试所有REST请求。它看起来像这样:

如何从多个Baqend表中删除所有数据?