2025-07-03 10:59:17 -04:00
|
|
|
import { SqlTransformer } from 'src/sql-tools/transformers/types';
|
2025-07-08 08:17:40 -04:00
|
|
|
import { DatabaseFunction } from 'src/sql-tools/types';
|
2025-04-07 15:12:12 -04:00
|
|
|
|
2025-07-08 08:17:40 -04:00
|
|
|
export const transformFunctions: SqlTransformer = (ctx, item) => {
|
2025-04-07 15:12:12 -04:00
|
|
|
switch (item.type) {
|
2025-07-03 10:59:17 -04:00
|
|
|
case 'FunctionCreate': {
|
2025-04-07 15:12:12 -04:00
|
|
|
return asFunctionCreate(item.function);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-03 10:59:17 -04:00
|
|
|
case 'FunctionDrop': {
|
2025-04-07 15:12:12 -04:00
|
|
|
return asFunctionDrop(item.functionName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default: {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-08 08:17:40 -04:00
|
|
|
export const asFunctionCreate = (func: DatabaseFunction): string => {
|
2025-04-07 15:12:12 -04:00
|
|
|
return func.expression;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const asFunctionDrop = (functionName: string): string => {
|
|
|
|
|
return `DROP FUNCTION ${functionName};`;
|
|
|
|
|
};
|