-
Notifications
You must be signed in to change notification settings - Fork 181
/
addToOperatorFamily.ts
35 lines (29 loc) · 1.03 KB
/
addToOperatorFamily.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 { Name, Reversible } from '../generalTypes';
import { removeFromOperatorFamily } from './removeFromOperatorFamily';
import type { OperatorListDefinition } from './shared';
import { operatorMap } from './shared';
export type AddToOperatorFamilyFn = (
operatorFamilyName: Name,
indexMethod: Name,
operatorList: OperatorListDefinition[]
) => string;
export type AddToOperatorFamily = Reversible<AddToOperatorFamilyFn>;
export const addToOperatorFamily = (
mOptions: MigrationOptions
): AddToOperatorFamily => {
const method: AddToOperatorFamily = (
operatorFamilyName,
indexMethod,
operatorList
) => {
const operatorFamilyNameStr = mOptions.literal(operatorFamilyName);
const operatorListStr = operatorList
.map(operatorMap(mOptions))
.join(',\n ');
return `ALTER OPERATOR FAMILY ${operatorFamilyNameStr} USING ${indexMethod} ADD
${operatorListStr};`;
};
method.reverse = removeFromOperatorFamily(mOptions);
return method;
};