-
Notifications
You must be signed in to change notification settings - Fork 180
/
dropFunction.ts
31 lines (25 loc) · 959 Bytes
/
dropFunction.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 { DropOptions, Name } from '../generalTypes';
import type { FunctionParam } from './shared';
export type DropFunctionOptions = DropOptions;
export type DropFunction = (
functionName: Name,
functionParams: FunctionParam[],
dropOptions?: DropFunctionOptions
) => string;
export function dropFunction(mOptions: MigrationOptions): DropFunction {
const _drop: DropFunction = (
functionName,
functionParams = [],
options = {}
) => {
const { ifExists = false, cascade = false } = options;
const ifExistsStr = ifExists ? ' IF EXISTS' : '';
const cascadeStr = cascade ? ' CASCADE' : '';
const paramsStr = formatParams(functionParams, mOptions);
const functionNameStr = mOptions.literal(functionName);
return `DROP FUNCTION${ifExistsStr} ${functionNameStr}${paramsStr}${cascadeStr};`;
};
return _drop;
}