-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (44 loc) · 1.06 KB
/
index.js
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
const squel = require('squel');
q = 'UNION("abc", SELECT(FIND("avg >= 10", "stud"), ["id", "sname"]))';
function OUTPUT(obj) {
console.log(obj.toString());
}
function SELECT(obj, fields) {
let s = squel.select();
for (let field in fields) {
s = s.field(fields[field]);
}
return s.from(obj);
}
function FIND(cond, obj) {
return squel.select()
.where(cond)
.from(obj);
}
function UNION(obj1, obj2) {
if (typeof obj1 === 'string') {
obj1 = SELECT(obj1, ["*"]);
}
if (typeof obj2 === 'string') {
obj2 = SELECT(obj2, ["*"]);
}
return obj1.union(obj2);
}
function EXCEPT(obj1, obj2) {
if (typeof obj1 === 'string') {
obj1 = SELECT(obj1, ["*"]);
}
if (typeof obj2 === 'string') {
obj2 = SELECT(obj2, ["*"]);
}
return obj1.union(obj2);
}
function INTERSECT(obj1, obj2) {
if (typeof obj1 === 'string') {
obj1 = SELECT(obj1, ["*"]);
}
if (typeof obj2 === 'string') {
obj2 = SELECT(obj2, ["*"]);
}
}
eval(`OUTPUT(${q});`);