if(!functionName||!returnType||!language||!body)thrownewError('createFunction missing some parameters. Did you pass functionName, returnType, language and body?');
if(!functionName||!returnType||!language||!body)thrownewError('createFunction missing some parameters. Did you pass functionName, returnType, language and body?');
conststatement=options&&options.force?'CREATE OR REPLACE FUNCTION':'CREATE FUNCTION';
return`CREATE FUNCTION ${functionName}(${paramList}) RETURNS ${returnType} AS $func$ BEGIN ${body} END; $func$ language '${language}'${expandedOptions};`;
return`${statement}${functionName}(${paramList}) RETURNS ${returnType} AS $func$ BEGIN ${body} END; $func$ language '${language}'${expandedOptionsArray};`;
* @param {string} functionName Name of SQL function to create
* @param {string} functionName Name of SQL function to create
* @param {Array} params List of parameters declared for SQL function
* @param {Array} params List of parameters declared for SQL function
* @param {string} returnType SQL type of function returned value
* @param {string} returnType SQL type of function returned value
* @param {string} language The name of the language that the function is implemented in
* @param {string} language The name of the language that the function is implemented in
* @param {string} body Source code of function
* @param {string} body Source code of function
* @param {Array} optionsArray Extra-options for creation
* @param {Array} optionsArray Extra-options for creation
* @param {Object} [options] query options
* @param {Object} [options] query options
* @param {boolean} options.force If force is true, any existing functions with the same parameters will be replaced. For postgres, this means using `CREATE OR REPLACE FUNCTION` instead of `CREATE FUNCTION`. Default is false