File tree Expand file tree Collapse file tree
__tests__/examples/exporter/postgres_exporter/output
src/core/analyzer/validator/elementValidators Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- CREATE OR REPLACE FUNCTION "public "." increment" (len_from integer , len_to integer )
1+ CREATE OR REPLACE FUNCTION "public "." increment" (" len_from" integer , " len_to" integer )
22RETURNS integer
33LANGUAGE plpgsql
44VOLATILE
5+ SECURITY INVOKER
56AS $$
67DECLARE
78 film_count INTEGER ;
@@ -14,7 +15,7 @@ DECLARE
1415 END;
1516$$;
1617
17- CREATE OR REPLACE FUNCTION "public "." simple_add" (a integer , b integer )
18+ CREATE OR REPLACE FUNCTION "public "." simple_add" (" a " integer , " b " integer )
1819RETURNS integer
1920LANGUAGE plpgsql
2021IMMUTABLE
Original file line number Diff line number Diff line change @@ -556,16 +556,17 @@ class PostgresExporter {
556556 }
557557
558558 static exportFunctions ( functionIds , model ) {
559+ const toSqlType = ( type ) => ( type || '' ) . replace ( / _ / g, ' ' ) ;
559560 return functionIds . map ( ( functionId ) => {
560561 const fn = model . functions [ functionId ] ;
561562 const schema = fn . schemaName || 'public' ;
562- const argList = ( fn . args || [ ] ) . map ( ( a ) => `${ a . name } ${ a . type } ` ) . join ( ', ' ) ;
563- const returnType = ( fn . returns || 'void' ) . replace ( / _ / g , ' ') ;
563+ const argList = ( fn . args || [ ] ) . map ( ( a ) => `" ${ a . name } " ${ toSqlType ( a . type ) } ` ) . join ( ', ' ) ;
564+ const returnType = toSqlType ( fn . returns || 'void' ) ;
564565 let line = `CREATE OR REPLACE FUNCTION "${ schema } "."${ fn . name } "(${ argList } )` ;
565566 line += `\nRETURNS ${ returnType } ` ;
566567 line += `\nLANGUAGE ${ fn . language || 'plpgsql' } ` ;
567568 line += `\n${ ( fn . behavior || 'volatile' ) . toUpperCase ( ) } ` ;
568- if ( fn . security === 'definer' ) line += '\nSECURITY DEFINER' ;
569+ line += `\nSECURITY ${ ( fn . security || 'invoker' ) . toUpperCase ( ) } ` ;
569570 line += '\nAS $$' ;
570571 line += `\n${ ( fn . body || '' ) . trim ( ) } ` ;
571572 line += '\n$$;\n' ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments