Changes between Version 20 and Version 21 of DeveloperGuidelines/EdenMobile/Services/emDB


Ignore:
Timestamp:
06/12/18 08:40:56 (7 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/EdenMobile/Services/emDB

    v20 v21  
    201201NB {{{limitby: [0,1]}}} can also be written as simply {{{limitby: 1}}}
    202202
    203 === Aggregation and Groupby ===
    204 
    205 Aggregates can be constructed from field expressions
    206 
    207 The {{{select()}}} method accepts an object with arguments as (optional) second parameter, e.g. {{{limitby}}} and {{{orderby}}}:
    208 
    209 {{{#!js
     203=== Aggregates and Groupby ===
     204
     205'''Aggregate expressions''' can be constructed from field expressions using operator functions, e.g.:
     206
     207{{{#!js
     208// The total (sum) of the field 'value':
     209var totalValue = table.$('value').sum();
     210}}}
     211
     212Currently supported operators are '''count''', '''sum''', '''avg''', '''min''', and '''max'''.
     213
     214Aggregate expressions can be used to extract the aggregate values from rows:
     215
     216{{{#!js
     217// The total (sum) of the field 'value':
     218var totalValue = table.$('value').sum();
     219...
     220// Access the total in a row
     221var value = row.$(totalValue);
     222}}}
     223
     224The {{{select()}}} method of Sets accepts a groupby option:
     225
     226{{{#!js
     227// Extract the total of values per location
     228var locationID = table.$('location_id'),
     229    totalValue = table.$('value').sum();
    210230set.select(
    211     [array of fields],
     231    [locationID, totalValue],
    212232    {
    213         limitby: [0,1],
    214         orderby: field
     233        groupby: locationID,
    215234    },
    216235    function(rows) {...}