MCPcopy
hub / github.com/dresende/node-orm2 / AggregateFunctions

Function AggregateFunctions

lib/AggregateFunctions.js:7–176  ·  view source on GitHub ↗
(opts)

Source from the content-addressed store, hash-verified

5module.exports = AggregateFunctions;
6
7function AggregateFunctions(opts) {
8 if (typeof opts.driver.getQuery !== "function") {
9 throw new ORMError('NO_SUPPORT', "This driver does not support aggregate functions");
10 }
11 if (!Array.isArray(opts.driver.aggregate_functions)) {
12 throw new ORMError('NO_SUPPORT', "This driver does not support aggregate functions");
13 }
14
15 var aggregates = [ [] ];
16 var group_by = null;
17 var used_distinct = false;
18
19 var appendFunction = function (fun) {
20 return function () {
21 var args = (arguments.length && Array.isArray(arguments[0]) ? arguments[0] : Array.prototype.slice.apply(arguments));
22
23 if (args.length > 0) {
24 aggregates[aggregates.length - 1].push({ f: fun, a: args, alias: aggregateAlias(fun, args) });
25 aggregates.push([]);
26 } else {
27 aggregates[aggregates.length - 1].push({ f: fun, alias: aggregateAlias(fun, args) });
28 }
29
30 if (fun === "distinct") {
31 used_distinct = true;
32 }
33
34 return proto;
35 };
36 };
37 var proto = {
38 groupBy: function () {
39 group_by = Array.prototype.slice.apply(arguments);
40 return this;
41 },
42 limit: function (offset, limit) {
43 if (typeof limit === "number") {
44 opts.limit = [ offset, limit ];
45 } else {
46 opts.limit = [ 0, offset ]; // offset = limit
47 }
48 return this;
49 },
50 order: function () {
51 opts.order = Utilities.standardizeOrder(Array.prototype.slice.apply(arguments));
52 return this;
53 },
54 select: function () {
55 if (arguments.length === 0) {
56 throw new ORMError('PARAM_MISMATCH', "When using append you must at least define one property");
57 }
58 if (Array.isArray(arguments[0])) {
59 opts.propertyList = opts.propertyList.concat(arguments[0]);
60 } else {
61 opts.propertyList = opts.propertyList.concat(Array.prototype.slice.apply(arguments));
62 }
63 return this;
64 },

Callers

nothing calls this directly

Calls 12

aggregateAliasFunction · 0.85
cbFunction · 0.85
addAggregateFunction · 0.85
funMethod · 0.80
selectMethod · 0.65
fromMethod · 0.65
whereMethod · 0.65
orderMethod · 0.65
limitMethod · 0.65
offsetMethod · 0.65
buildMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected