deno.land / x / pg_mem@2.8.1 / transforms / aggregations / sum.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { AggregationComputer, AggregationGroupComputer, IValue, nil, QueryError, _ISelection, _IType, _Transaction } from '../../interfaces-private.ts';import { ExprCall } from 'https://deno.land/x/pgsql_ast_parser@12.0.1/mod.ts';import { buildValue } from '../../parser/expression-builder.ts';import { Types } from '../../datatypes/index.ts';import { nullIsh } from '../../utils.ts';import { withSelection } from '../../parser/context.ts';
class SumExpr implements AggregationComputer<number> {
constructor(private exp: IValue) { }
get type(): _IType<any> { return Types.bigint; }
createGroup(t: _Transaction): AggregationGroupComputer<number> { let val: number | nil = null; return { feedItem: (item) => { const value = this.exp.get(item, t); if (!nullIsh(value)) { val = nullIsh(val) ? value : val + value; } }, finish: () => val, } }}
export function buildSum(this: void, base: _ISelection, call: ExprCall) { return withSelection(base, () => { const args = call.args; if (args.length !== 1) { throw new QueryError('SUM expects one argument, given ' + args.length); }
const what = buildValue(args[0]); return new SumExpr(what);
});}
pg_mem

Version Info

Tagged at
a year ago