如何从多个 Baqend 表中删除所有数据?
How can I delete all data from multiple Baqend tables?
我需要以编程方式(不在仪表板中)删除多个表中的所有行。有 API 吗?我在 documentation.
中找不到它
你是对的,目前没有记录。但是,您可以在我们的 API Explorer 中找到 REST 调用,尽管您没有从 JS SDK 中获取语法糖。 REST 调用是 DELETE
到 /db/{bucket}
,其中 bucket
是要删除的 Table 的名称。使用 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.
您还可以尝试 API Explorer 中的所有 REST 请求。它看起来像这样:
我需要以编程方式(不在仪表板中)删除多个表中的所有行。有 API 吗?我在 documentation.
中找不到它你是对的,目前没有记录。但是,您可以在我们的 API Explorer 中找到 REST 调用,尽管您没有从 JS SDK 中获取语法糖。 REST 调用是 DELETE
到 /db/{bucket}
,其中 bucket
是要删除的 Table 的名称。使用 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 thenode
role) you can skip the login.
您还可以尝试 API Explorer 中的所有 REST 请求。它看起来像这样: