Delete data from a Fliplet Datasource

PRE-REQUISITES
For the following code examples to work, you will need to add Fliplet’s Data Sources API to your app. To add it follow the steps referenced here.

Removing an entry (ie a row) of data from a Fliplet Data Source

To remove an entry (i.e. a row in the data source) you need to know that entry’s ID. You can find the entry’s ID (in this case we’re locating a row where the name is “John”) and delete the row using the .removeById() command.

JavaScript


var dataSourceConnection;

Fliplet.DataSources.connect(265)
  .then(function (connection) {
    dataSourceConnection = connection;

    return connection.findOne({
      where: { name: 'John' }
    });
  })
  .then(function (user) {
    if (!user) {
      return Promise.reject('User not found');
    }

    return dataSourceConnection.removeById(user.id);
  });

If you don’t want to delete the entire row but instead want to delete a value in the row, this is equivalent to updating a column with a blank value. For examples on how to save and overwrite data in the data source please go here.

What if you have to delete multiple rows?
I use the code below to delete multiple lines but some times it takes too long and loads the page before the rows can be deleted

I found if I insert the code in the global javascript it works perfect.

.then(function(records) {
//console.log(records);
var loops = records.length;
alert(loops);
for (let i = 0; i < loops; i++) {
dataSourceConnection.removeById(records[i].id); //remove return?
//alert(i);
}
});