-
Notifications
You must be signed in to change notification settings - Fork 180
/
renameFunction.ts
31 lines (25 loc) · 1.01 KB
/
renameFunction.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
import type { MigrationOptions } from '../../types';
import { formatParams } from '../../utils';
import type { Name, Reversible } from '../generalTypes';
import type { FunctionParam } from './shared';
export type RenameFunctionFn = (
oldFunctionName: Name,
functionParams: FunctionParam[],
newFunctionName: Name
) => string;
export type RenameFunction = Reversible<RenameFunctionFn>;
export function renameFunction(mOptions: MigrationOptions): RenameFunction {
const _rename: RenameFunction = (
oldFunctionName,
functionParams = [],
newFunctionName
) => {
const paramsStr = formatParams(functionParams, mOptions);
const oldFunctionNameStr = mOptions.literal(oldFunctionName);
const newFunctionNameStr = mOptions.literal(newFunctionName);
return `ALTER FUNCTION ${oldFunctionNameStr}${paramsStr} RENAME TO ${newFunctionNameStr};`;
};
_rename.reverse = (oldFunctionName, functionParams, newFunctionName) =>
_rename(newFunctionName, functionParams, oldFunctionName);
return _rename;
}