query.ts 2.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
 * Departamento de Informatica - Universidade Federal do Parana
 *
 * This file is part of blend.
 *
 * blend is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * blend is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with blend.  If not, see <http://www.gnu.org/licenses/>.
 */

21
22
import { Metric } from "../core/metric";
import { Dimension } from "../core/dimension";
23
import { Clause } from "../core/clause";
24

25
26
27
/**
 * Internal representation of a query in BlenDB perspective.
 */
rafaelatc3sl's avatar
rafaelatc3sl committed
28
export interface QueryOpts {
29
30
31
32
33
34
35
36
    /** Set of metrics of the query. */
    metrics: Metric[];
    /** Set of dimensions of the query. */
    dimensions: Dimension[];
    /** Set of clauses of the query. */
    clauses?: Clause[];
    /** List of metrics and dimensions to sort the query. */
    sort?: (Metric|Dimension)[];
37
}
rafaelatc3sl's avatar
rafaelatc3sl committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

export class Query {
    /** Set of metrics of the query. */
    public readonly metrics: Metric[];
    /** Set of dimensions of the query. */
    public readonly dimensions: Dimension[];
    /** Set of clauses of the query. */
    public readonly clauses: Clause[];
    /** List of metrics and dimensions to sort the query. */
    public readonly sort: (Metric|Dimension)[];
    /**
     * Create Query
     * @param opts - Parameters required to create a query.
     */
    constructor(opts: QueryOpts){
        this.metrics = opts.metrics.map((i) => i);
        this.dimensions = opts.dimensions.map((i) => i);
        this.clauses = (opts.clauses) ? opts.clauses.map((i) => i) : [];
        this.sort = (opts.sort) ? opts.sort.map((i) => i) : [];
    }
}