forked from martin-pabst/SQL-IDE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLMethods.ts
More file actions
84 lines (69 loc) · 3.69 KB
/
SQLMethods.ts
File metadata and controls
84 lines (69 loc) · 3.69 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { SQLBaseType, SQLType } from "./SQLTypes.js";
export class SQLMethodParameter {
type: SQLType;
constructor(public identifier: string, type: string){
this.type = SQLBaseType.getBaseType(type);
}
}
export class SQLMethod {
acceptsStarParameter: boolean = false;
public returnType: SQLType;
constructor(public identifier: string, public isAggregating: boolean, returnType: string, public parameters: SQLMethodParameter[]){
this.returnType = SQLBaseType.getBaseType(returnType);
}
}
export class SQLMethodStore {
static instance: SQLMethodStore;
public methods: SQLMethod[] = [];
static getInstance():SQLMethodStore {
if(this.instance == null){
this.instance = new SQLMethodStore();
}
return this.instance;
}
constructor(){
this.pushOneParameterMethod("abs" ,"float", "float");
this.pushOneParameterMethod("sin" ,"float", "float");
this.pushOneParameterMethod("cos" ,"float", "float");
this.pushOneParameterMethod("tan" ,"float", "float");
this.pushOneParameterMethod("max" ,"integer", "integer");
this.pushOneParameterMethod("max" ,"float", "float");
this.pushOneParameterMethod("max" ,"date", "date");
this.pushOneParameterMethod("max" ,"time", "time");
this.pushOneParameterMethod("max" ,"datetime", "datetime");
this.pushOneParameterMethod("max" ,"timestamp", "timestamp");
this.pushOneParameterMethod("min" ,"integer", "integer");
this.pushOneParameterMethod("min" ,"float", "float");
this.pushOneParameterMethod("min" ,"date", "date");
this.pushOneParameterMethod("min" ,"time", "time");
this.pushOneParameterMethod("min" ,"datetime", "datetime");
this.pushOneParameterMethod("min" ,"timestamp", "timestamp");
this.pushOneParameterMethod("avg" ,"integer", "integer");
this.pushOneParameterMethod("avg" ,"float", "float");
this.pushOneParameterMethod("sum" ,"float", "float");
this.pushOneParameterMethod("sum" ,"integer", "integer");
this.pushOneParameterMethod("concat" ,"text", "text");
this.pushOneParameterMethod("upper" ,"text", "text");
this.pushOneParameterMethod("lower" ,"text", "text");
this.pushOneParameterMethod("length" ,"integer", "text");
this.pushOneParameterMethod("month" , "integer","date");
this.pushOneParameterMethod("day" , "integer","date");
this.pushOneParameterMethod("year" , "integer","date");
this.pushOneParameterMethod("round" , "integer","float");
let countMethod = new SQLMethod("count", true, "integer", [new SQLMethodParameter("spalte", "text")]);
countMethod.acceptsStarParameter = true;
this.methods.push(countMethod);
let strftimeMethod = new SQLMethod("strftime", false, "text", [new SQLMethodParameter("formatstring", "text"), new SQLMethodParameter("date", "date")]);
strftimeMethod.acceptsStarParameter = true;
this.methods.push(strftimeMethod);
let round2Params = new SQLMethod("round", false, "float", [new SQLMethodParameter("number", "float"), new SQLMethodParameter("digits", "integer")]);
round2Params.acceptsStarParameter = false;
this.methods.push(round2Params);
}
getMethods(identifier: string){
return this.methods.filter(m => m.identifier == identifier.toLowerCase());
}
pushOneParameterMethod(identifier: string, returnType: string, parameterType: string){
this.methods.push(new SQLMethod(identifier, true, returnType, [new SQLMethodParameter("spalte", parameterType)]));
}
}