Helper for manipulation with data, stored locally in (TubCachedData format).
This module shared between client & server. In case of server we use it together with dataLoader, in case of client - inside SyncConnection.select to handle operations with entity data cached in IndexedDB.
For server-side samples see ubm_forms.doSelect method implementation.
$App.connection.run({
entity: 'tst_IDMapping',
method: 'addnew',
fieldList: ['ID', 'code']
}).then(function(result){
// here result in array-of-array format
// [{"entity":"tst_IDMapping","method":"addnew","fieldList":["ID","code"],
// "__fieldListExternal":["ID","code"],
// "resultData":{"fields":["ID","code"],"rowCount": 1, "data":[[3500000016003,null]]}}]
var objArray = UB.LocalDataStore.selectResultToArrayOfObjects(result);
// transform array-of-array result representation to array-of-object
console.log(objArray);
// now result in more simple array-of-object format: [{ID: 12312312312, code: null}]
})
Methods
# arrayOfObjectsToSelectResult (arrayOfObject: Array.<object>, attributeNames: Array.<string>) → Array.<Array> static
Reverse conversion to LocalDataStore.selectResultToArrayOfObjects.
//Transform array of object to array of array using passed attributes array
LocalDataStore.arrayOfObjectsToSelectResult([{a: 1, b: 'as'}, {b: 'other', a: 12}], ['a', 'b']);
// result is: [[1, "as"], [12, "other"]]
# byID (cachedData: TubCachedData, IDValue: number) → Object static
A helper for search cached data by row ID
Return:
new filtered & sorted array
Arguments:
cachedData
: TubCachedDataData, retrieved from cache
IDValue
: numberrow ID
# convertResponseDataToJsTypes (domain: UBDomain, serverResponse) → * static
Convert raw server response data to javaScript data according to attribute types
Arguments:
domain
: UBDomainserverResponse
:
# doFilterAndSort (cachedData: TubCachedData, ubql: UBQL) → Object static
Perform local filtration and sorting of data array according to ubql whereList & order list.
WARNING - sub-queries are not supported.
Return:
new filtered & sorted array
Arguments:
cachedData
: TubCachedDataData, retrieved from cache
ubql
: UBQLInitial server request
# doFiltration (cachedData: TubCachedData, ubql: UBQL, skipSubQueriesAndCustomopt: boolean) → Array.<Array> static
Apply ubql.whereList to data array and return new array contain filtered data
Arguments:
cachedData
: TubCachedDataData, retrieved from cache
ubql
: UBQLskipSubQueriesAndCustom
= false: booleanSkip
subquery
andcustom
conditions instead of throw. Can be used to estimate record match some of where conditions
# doSorting (filteredArray: Array.<Array>, cachedData: TubCachedData, ubRequest: object) static
Apply ubRequest.orderList to inputArray (inputArray is modified)
Arguments:
filteredArray
: Array.<Array>cachedData
: TubCachedDataubRequest
: object
# flatten (requestedFieldList: Array.<string>, cachedData: TubCachedData) → Object static
Flatten cached data (or result of LocalDataStore.doFilterAndSort.resultData ) to Object expected by TubDataStore.initialize Flatten format (faster than [{}..] format). CachedData may contain more field or field in order not in requestedFieldList - in this case we use expectedFieldList.
Arguments:
requestedFieldList
: Array.<string>Array of attributes to transform to. Can be ['*'] - in this case we return all cached attributes
cachedData
: TubCachedData
// consider we have cached data in variable filteredData.resultData
// to initialize dataStore with cached data:
mySelectMethod = function(ctxt){
const fieldList = ctxt.mParams.fieldList;
resp = LocalDataStore.flatten(fieldList, filteredData.resultData);
ctxt.dataStore.initFromJSON(resp);
}
# iso8601ParseAsDate (val: string) → Date static
Convert UnityBase server date response to Date object. Date response is a day with 00 time (2015-07-17T00:00Z), to get a real date we must add current timezone shift
# selectResultToArrayOfObjects (selectResult: Object, fieldAliasopt: Object.<string, string>) → Array.<object> static
Transform result of SyncConnection.select response from Array of Array representation to Array of Object
Arguments:
LocalDataStore.selectResultToArrayOfObjects({resultData: {
data: [['row1_attr1Val', 1], ['row2_attr2Val', 22]],
fields: ['attrID.name', 'attr2']}
});
// result is:
// [{"attrID.name": "row1_attr1Val", attr2: 1},
// {"attrID.name": "row2_attr2Val", attr2: 22}
// ]
// object keys simplify by passing fieldAliases
LocalDataStore.selectResultToArrayOfObjects({resultData: {
data: [['row1_attr1Val', 1], ['row2_attr2Val', 22]],
fields: ['attrID.name', 'attr2']}
}, {'attrID.name': 'attr1Name'});
// result is:
// [{attr1Name: "row1_attr1Val", attr2: 1},
// {attr1Name: "row2_attr2Val", attr2: 22}
// ]
# truncTimeToUtcNull (v: Date) → Date static
Convert a local DateTime to Date with zero time in UTC0 timezone as expected by UB server for Date attributes
Arguments:
v
: Date
Types
# TubCachedData inner
Format for data, stored in client-side cache
Properties