Interface: DataMapping

QuickNav

DataMapping

Interface for DataMapping which can be supplied to shredders/unshredders and queryHandlers

Methods

mapFields(item) → {Item}

Field mapping function which takes an item and returns the mapped item
Parameters:
Name Type Description
item Item
Returns:
Returns the mapped item.
This is typically used when there is a need to tranform the data before
it is stored in the database. One use case would be for converting ISO Datetime
string values to numbers to enable querying and sorting in the DB. e.g.

dataMapping.mapFields = function(item) {
  var mappedItem = {};
  mappedItem.data = {};
  Object.keys(item.data).forEach(function(field) {
    if (field == 'hireDate') {
      var date = new Date(item.data[field]);
      mappedItem.data[field] = date.getTime();
    } else {
      mappedItem.data[field] = item.data[field];
    }
  });
  mappedItem.metadata = item.metadata;
  return mappedItem;
};

Type
Item

mapFilterCriterion(item) → {AttributeFilter|CompoundFilter}

FilterCriterion mapping function which takes filterCriterion and returns the mapped filterCriterion
Parameters:
Name Type Description
item AttributeFilter | CompoundFilter
Returns:
Returns the mapped filterCriterion.
This is required when mapFields was used and queries are processed. e.g.

dataMapping.mapFilterCriterion = function(filterCriterion) {
  if (filterCriterion && filterCriterion.attribute == 'hireDate') {
    filterCriterion.value = (new Date(filterCriterion.value)).getTime();
  }
  return filterCriterion;
};

Type
AttributeFilter | CompoundFilter

unmapFields(item) → {Item}

Field unmapping function which takes a mapped item and returns the item
Parameters:
Name Type Description
item Item
Returns:
Returns the unmapped item.
This is required when mapFields was used so that we can transform
back the data. e.g.

dataMapping.unmapFields = function(item) {
  var unmappedItem = {};
  unmappedItem.data = {};
  Object.keys(item.data).forEach(function(field) {
    if (field == 'hireDate') {
      var date = new Date(item.data[field]);
      unmappedItem.data[field] = date.toISOString();
    } else {
      unmappedItem.data[field] = item.data[field];
    }
  });
  unmappedItem.metadata = item.metadata;
  return unmappedItem;
};

Type
Item