From f07d2f93029982bac38b0b8d7d591a1c8e8e556a Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Thu, 24 Nov 2016 13:27:32 +0100 Subject: [PATCH] Remove the no_params from client generator #302 --- client/renderer/interface.yaml | 2 -- client/renderer/sql-template-renderer | 10 +++------- client/renderer/templates/20_public_functions.erb | 11 ++++------- client/renderer/templates/30_plproxy_functions.erb | 12 +++--------- client/renderer/templates/90_grant_execute.erb | 2 +- 5 files changed, 11 insertions(+), 26 deletions(-) diff --git a/client/renderer/interface.yaml b/client/renderer/interface.yaml index be758f9..a40c99d 100644 --- a/client/renderer/interface.yaml +++ b/client/renderer/interface.yaml @@ -323,7 +323,6 @@ - name: obs_dumpversion return_type: text - no_params: true params: - {} @@ -381,7 +380,6 @@ - name: cdb_service_params return_type: SETOF cdb_dataservices_client.service_params multi_row: true - no_params: true params: - {} diff --git a/client/renderer/sql-template-renderer b/client/renderer/sql-template-renderer index af558d0..2516a09 100755 --- a/client/renderer/sql-template-renderer +++ b/client/renderer/sql-template-renderer @@ -36,10 +36,6 @@ class SqlTemplateRenderer @function_signature['multi_row'] end - def no_params - @function_signature['no_params'] - end - def user_config_key @function_signature['user_config_key'] end @@ -49,11 +45,11 @@ class SqlTemplateRenderer end def params - @function_signature['params'].reject(&:empty?).map { |p| "#{p['name']}"}.join(', ') + @function_signature['params'].reject(&:empty?).map { |p| "#{p['name']}"} end def params_with_type - @function_signature['params'].reject(&:empty?).map { |p| "#{p['name']} #{p['type']}" }.join(', ') + @function_signature['params'].reject(&:empty?).map { |p| "#{p['name']} #{p['type']}" } end def params_with_type_and_default @@ -64,7 +60,7 @@ class SqlTemplateRenderer "#{p['name']} #{p['type']}" end end - return parameters.join(', ') + return parameters end end diff --git a/client/renderer/templates/20_public_functions.erb b/client/renderer/templates/20_public_functions.erb index 5de10bd..88db53d 100644 --- a/client/renderer/templates/20_public_functions.erb +++ b/client/renderer/templates/20_public_functions.erb @@ -4,7 +4,7 @@ -- These are the only ones with permissions to publicuser role -- and should also be the only ones with SECURITY DEFINER -CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %> (<%= params_with_type_and_default %>) +CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %> (<%= params_with_type_and_default.join(' ,') %>) RETURNS <%= return_type %> AS $$ DECLARE <% if not multi_row %>ret <%= return_type %>;<% end %> @@ -21,15 +21,12 @@ BEGIN END IF; <% if multi_row %> RETURN QUERY - SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(username, orgname, <%= params %>); + SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= ['username', 'orgname'].concat(params).join(', ') %>); <% elsif multi_field %> - SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(username, orgname, <%= params %>) INTO ret; - RETURN ret; - <% elsif no_params %> - SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(username, orgname) INTO ret; + SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= ['username', 'orgname'].concat(params).join(', ') %>) INTO ret; RETURN ret; <% else %> - SELECT <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(username, orgname, <%= params %>) INTO ret; + SELECT <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= ['username', 'orgname'].concat(params).join(', ') %>) INTO ret; RETURN ret; <% end %> END; diff --git a/client/renderer/templates/30_plproxy_functions.erb b/client/renderer/templates/30_plproxy_functions.erb index 66a6727..2d5dfe3 100644 --- a/client/renderer/templates/30_plproxy_functions.erb +++ b/client/renderer/templates/30_plproxy_functions.erb @@ -1,15 +1,9 @@ -<% if no_params %> -CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %> (username text, organization_name text) -<% else %> -CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %> (username text, organization_name text, <%= params_with_type_and_default %>) -<% end %> +CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %> (<%= ['username text', 'organization_name text'].concat(params_with_type_and_default).join(', ') %>) RETURNS <%= return_type %> AS $$ CONNECT <%= DATASERVICES_CLIENT_SCHEMA %>._server_conn_str(); <% if multi_field %> - SELECT * FROM <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (username, organization_name, <%= params %>); - <% elsif no_params %> - SELECT * FROM <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (username, organization_name); + SELECT * FROM <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (<%= ['username', 'organization_name'].concat(params).join(', ') %>); <% else %> - SELECT <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (username, organization_name, <%= params %>); + SELECT <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (<%= ['username', 'organization_name'].concat(params).join(', ') %>); <% end %> $$ LANGUAGE plproxy; diff --git a/client/renderer/templates/90_grant_execute.erb b/client/renderer/templates/90_grant_execute.erb index 7d0c030..bde5944 100644 --- a/client/renderer/templates/90_grant_execute.erb +++ b/client/renderer/templates/90_grant_execute.erb @@ -1 +1 @@ -GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %>(<%= params_with_type %>) TO publicuser; \ No newline at end of file +GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %>(<%= params_with_type.join(', ') %>) TO publicuser;