-
Notifications
You must be signed in to change notification settings - Fork 180
/
shared.ts
73 lines (54 loc) · 1.45 KB
/
shared.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
68
69
70
71
72
73
import { applyType } from '../../utils';
import type { Type } from '../generalTypes';
import type { ColumnDefinitions } from '../tables';
export interface SequenceOptions {
type?: Type;
increment?: number;
minvalue?: number | null | false;
maxvalue?: number | null | false;
start?: number;
cache?: number;
cycle?: boolean;
owner?: string | null | false;
}
export function parseSequenceOptions(
typeShorthands: ColumnDefinitions | undefined,
options: SequenceOptions
): string[] {
const { type, increment, minvalue, maxvalue, start, cache, cycle, owner } =
options;
const clauses: string[] = [];
if (type) {
clauses.push(`AS ${applyType(type, typeShorthands).type}`);
}
if (increment) {
clauses.push(`INCREMENT BY ${increment}`);
}
if (minvalue) {
clauses.push(`MINVALUE ${minvalue}`);
} else if (minvalue === null || minvalue === false) {
clauses.push('NO MINVALUE');
}
if (maxvalue) {
clauses.push(`MAXVALUE ${maxvalue}`);
} else if (maxvalue === null || maxvalue === false) {
clauses.push('NO MAXVALUE');
}
if (start) {
clauses.push(`START WITH ${start}`);
}
if (cache) {
clauses.push(`CACHE ${cache}`);
}
if (cycle) {
clauses.push('CYCLE');
} else if (cycle === false) {
clauses.push('NO CYCLE');
}
if (owner) {
clauses.push(`OWNED BY ${owner}`);
} else if (owner === null || owner === false) {
clauses.push('OWNED BY NONE');
}
return clauses;
}