-
Notifications
You must be signed in to change notification settings - Fork 180
/
dropOperator.ts
35 lines (27 loc) · 947 Bytes
/
dropOperator.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
import type { MigrationOptions } from '../../types';
import type { DropOptions, Name } from '../generalTypes';
export interface DropOperatorOptions extends DropOptions {
left?: Name;
right?: Name;
}
export type DropOperator = (
operatorName: Name,
dropOptions?: DropOperatorOptions
) => string;
export function dropOperator(mOptions: MigrationOptions): DropOperator {
const _drop: DropOperator = (operatorName, options = {}) => {
const {
left = 'none',
right = 'none',
ifExists = false,
cascade = false,
} = options;
const operatorNameStr = mOptions.schemalize(operatorName);
const leftStr = mOptions.literal(left);
const rightStr = mOptions.literal(right);
const ifExistsStr = ifExists ? ' IF EXISTS' : '';
const cascadeStr = cascade ? ' CASCADE' : '';
return `DROP OPERATOR${ifExistsStr} ${operatorNameStr}(${leftStr}, ${rightStr})${cascadeStr};`;
};
return _drop;
}