-
Notifications
You must be signed in to change notification settings - Fork 1
/
parameterized-condition.ts
68 lines (57 loc) · 1.77 KB
/
parameterized-condition.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { ParameterList, ParameterType } from '../';
/**
* A type that holds a condition object and any associated parameters.
*/
export class ParameterizedCondition {
/**
* Initialize the condition.
* @param cond - A condition object that can be lexed, parsed, and compiled.
* @param paramList - Any parameters referenced in the condition object.
*/
constructor(
private cond: object,
private paramList: ParameterList) {
}
/**
* Get the condition object.
*/
getCond(): object {
return this.cond;
}
/**
* Get the parameters.
*/
getParams(): ParameterType {
return this.paramList.getParams();
}
/**
* Get the [[ParameterList]].
*/
getParameterList(): ParameterList {
return this.paramList;
}
/**
* Convert cond and param objects into a ParameterizedCondition.
* @param cond An condition object that can be transpiled into a SQL where
* clause.
* @param parms Parameter replacements for the condition.
*/
static normalize(cond?: object, params?: ParameterType): ParameterizedCondition;
/**
* Do-nothing, identity normailization. (This method just returns cond.)
* @param cond A ParameterizedCondition object built with a ConditionBuilder.
*/
static normalize(cond: ParameterizedCondition): ParameterizedCondition;
/**
* Given cond and params object or a ParameterizedCondition, normalize to a
* ParameterizedCondition.
*/
static normalize(cond: object | ParameterizedCondition, params?: ParameterType): ParameterizedCondition {
if (cond instanceof ParameterizedCondition)
return cond;
const paramList = new ParameterList();
for (const key in params)
paramList.addParameter(key, params[key]);
return new ParameterizedCondition(cond, paramList);
}
}