Fliplet DataSources JS APIs

The fliplet-datasources package contains the following namespaces:


Data Sources

Get the list of data sources for the current organization

Fliplet.DataSources.get().then(function (dataSources) {});

Create a new data source

Fliplet.DataSources.create({
  name: 'foo',
  organizationId: 1 // optional
}).then(function (dataSource) {
  // created
});

Connect to a data source, given its ID

// All options are optional
var options = {
  offline: true // By default on native platform it connects to offline DB. Set this option to false to connect to api's
}

Fliplet.DataSources.connect(dataSourceId, options).then(function (connection) {
  // check below for usages of the connection
});

Once you get a connection, you can use the following methods to find, insert, update and delete data.

Fetch all records from a data source

// use "find" with no options to get all entries
connection.find().then(function (records) {

});
// use limit and offset for pagination
connection.find({ limit: 50, offset: 10 }).then(function (records) {

});

Full example:

Fliplet.DataSources.connect(1).then(function (connection) {
  return connection.find({ limit: 1000 });
}).then(function (records) {
  records.forEach(function (row) {
    $('foo').append(row.data.bar)
  });
});

Find for specific records

connection.find({
  where: { name: 'John' },
  limit: 1
}).then(function (records) {

});

Query a data source

// All options are optional
var options = {
  type: "select" // select(default)/update/delete
  where: { name: 'John' },
  attributes: ["name", "country"],
  dataSourceEntryId: 123
};

connection.query(options).then(function (records) {

});

Find a record by its ID

connection.findById(1).then(function (record) {

});

Replace the contents of the data source with new records

connection.replaceWith([
  { id: 1, name: 'Alice' },
  { id: 2, name: 'Bob', email: 'bob@example.org' }
]).then(function onComplete() {

});

Insert an array of new records into a data source

connection.append([
  { id: 3, name: 'Nick' },
  { id: 4, name: 'Ian', email: 'ian@example.org' }
]).then(function onComplete() {

});

Insert a single record into the data source

connection.insert({
  id: 3,
  name: 'Bill'
});

You can also pass a FormData object to upload files using a multipart request. When uploading files, you can also specify the MediaFolder where files should be stored to:

connection.insert(FormData, {
  mediaFolderId: 123
});

Update a record

connection.update(123, {
  name: 'Bill'
});

You can also pass a FormData object to upload files using a multipart request. When uploading files, you can also specify the MediaFolder where files should be stored to:

connection.update(123, FormData, {
  mediaFolderId: 456
});

Import a file into the data sources

connection.import(FormData).then(function onSuccess() {});

Remove a record by its ID

connection.removeById(1).then(function onRemove() {});