-
Notifications
You must be signed in to change notification settings - Fork 15
/
join.ts
30 lines (24 loc) · 834 Bytes
/
join.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
import { replaceParams } from "./util.ts";
export class Join {
value: string = null;
constructor(type: string, readonly table: string, readonly alias?: string) {
const name = alias ? "?? ??" : "??";
this.value = replaceParams(`${type} ${name}`, [table, alias]);
}
static inner(table: string, alias?: string): Join {
return new Join("INNER JOIN", table, alias);
}
static full(table: string, alias?: string): Join {
return new Join("FULL OUTER JOIN", table, alias);
}
static left(table: string, alias?: string): Join {
return new Join("LEFT OUTER JOIN", table, alias);
}
static right(table: string, alias?: string): Join {
return new Join("RIGHT OUTER JOIN", table, alias);
}
on(a: string, b: string) {
this.value += replaceParams(` ON ?? = ??`, [a, b]);
return this;
}
}