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.

You may want to know if some data exists or if it doesn’t, take certain actions to fill it in. Assuming the data was stored on a Fliplet data source you could use the following code.

var dataSourceConnection;

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

    return connection.findOne({
      where: {
        'Email': 'hello@fliplet.com'
      }
    });
  }).then(function (entry) {
    // If no entry found with the hello@fliplet.com email
    if (!entry) {
      dataSourceConnection.insert({
        'Email': 'hello@fliplet.com',
        'Created at': new Date().toISOString();
      });
    }
  });

The code connects with a data source, then looks for an entry with an email address of ‘hello@fliplet.com’. If it exists no further action is taken. If it doesn’t, then a new entry is created with the email address and the date at which the entry was created is stored.