Saving and retrieving data for your app from Fliplet’s cloud based Data Sources
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.
Documentation for all endpoints related to DS saving is here: Data Sources JS APIs | Fliplet Developers Documentation
Saving new data to the data source
The example code below connects to a data source with an ID of ‘18798’. Once it has connected, it then inserts a new row and adds the value “Bill” to the column titled ‘name’. If the column doesn’t already exist it will be created automatically to ensure the data is saved.
Fliplet.DataSources.connect(18798)
.then(function (connection) {
return connection.insert([
{
name: 'Nick',
email: 'nick@example.org'
}
]);
})
.then(function (results) {
// Will return the added entries data
});
If you would like to insert more than one record at once then it is recommended you use the commit endpoint documented here: Data Sources JS APIs | Fliplet Developers Documentation
Note: Please pay attention to the input parameters and make sure you set them correctly.
Fliplet.DataSources.connect(18798).then(function (connection) {
return connection.commit({
entries: [
// insert a new entry
{ data: { foo: "bar" } },
// update the entry with ID 123
{ id: 123, data: { foo: "barbaz" } },
],
// delete the entry with ID 456
delete: [456],
// ensure existing entries are unaffected
append: true,
// keep remote columns not sent with
// the updates of entry ID 123
extend: true,
});
});
Updating entries in the data source
If you would like to update only some entries in the DS. You need to use the record id in order to update entries.
You can find this id by connecting to the DS and reading the entries. Each entry will have a id property that can be used for updating purposes.
Fliplet.DataSources.connect(18798).then(function (connection) {
connection.update(123, {
name: "Bill",
});
});