Sven D Sven D -4 years ago 153
Javascript Question

How can I delete all data from multiple Baqend tables?

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.

Answer Source

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:

    DB.login("userWithAdminRole", "<password>").then(function() {
        return DB.send(new DB.message.TruncateBucket('<table>'));
    }).then(function () {
    }).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.

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

API Explorer

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download