Adding OBS_DumpVersion function

This commit is contained in:
Carla Iriberri 2016-07-11 18:25:39 +02:00
parent 9c068fa45e
commit 5bc2d974ac
5 changed files with 27 additions and 5 deletions

View File

@ -321,3 +321,9 @@
params:
- { name: geom, type: Geometry }
- { name: timespan, type: text, default: 'NULL'}
- name: obs_dumpversion
return_type: text
no_params: true
params:
- {}

View File

@ -36,6 +36,10 @@ 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
@ -45,15 +49,15 @@ class SqlTemplateRenderer
end
def params
@function_signature['params'].map { |p| p['name'] }.join(', ')
@function_signature['params'].reject(&:empty?).map { |p| "#{p['name']}"}.join(', ')
end
def params_with_type
@function_signature['params'].map { |p| "#{p['name']} #{p['type']}" }.join(', ')
@function_signature['params'].reject(&:empty?).map { |p| "#{p['name']} #{p['type']}" }.join(', ')
end
def params_with_type_and_default
parameters = @function_signature['params'].map do |p|
parameters = @function_signature['params'].reject(&:empty?).map do |p|
if not p['default'].nil?
"#{p['name']} #{p['type']} DEFAULT #{p['default']}"
else

View File

@ -25,10 +25,12 @@ BEGIN
<% 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;
RETURN ret;
<% else %>
SELECT <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(username, orgname, <%= params %>) INTO ret;
RETURN ret;
<% end %>
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;

View File

@ -1,10 +1,15 @@
<% 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 %>
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);
<% else %>
SELECT <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (username, organization_name, <%= params %>);
<% end %>
$$ LANGUAGE plproxy;

View File

@ -0,0 +1,5 @@
CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_dumpversion(username text, orgname text)
RETURNS text AS $$
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
SELECT cdb_observatory.obs_dumpversion();
$$ LANGUAGE plproxy;