Add properties for user and geocoder config keys instead of hardcode it in the template

This commit is contained in:
Mario de Frutos 2015-11-23 13:09:03 +01:00
parent e09af1463d
commit 963da6c5c7
3 changed files with 30 additions and 4 deletions

View File

@ -8,11 +8,11 @@ CREATE OR REPLACE FUNCTION <%= GEOCODER_CLIENT_SCHEMA %>.<%= name %> (<%= params
RETURNS <%= return_type %> AS $$
DECLARE
ret <%= return_type %>;
user_config JSON;
geocoder_config JSON;
user_config json;
geocoder_config json;
BEGIN
SELECT cartodb.CDB_Conf_GetConf('user_config') INTO user_config;
SELECT cartodb.CDB_Conf_GetConf('geocoder_config') INTO geocoder_config;
SELECT cartodb.CDB_Conf_GetConf('<%= user_config_key %>') INTO user_config;
SELECT cartodb.CDB_Conf_GetConf('<%= geocoder_config_key %>') INTO geocoder_config;
SELECT <%= GEOCODER_CLIENT_SCHEMA %>._<%= name %>(session_user, user_config, geocoder_config, <%= params %>) INTO ret;
RETURN ret;
END;

View File

@ -1,33 +1,45 @@
---
- name: geocode_admin0_polygon
return_type: Geometry
user_config_key: user_config
geocoder_config_key: geocoder_config
params:
- { name: country_name, type: text }
- name: geocode_admin1_polygon
return_type: Geometry
user_config_key: user_config
geocoder_config_key: geocoder_config
params:
- { name: admin1_name, type: text }
- name: geocode_admin1_polygon
return_type: Geometry
user_config_key: user_config
geocoder_config_key: geocoder_config
params:
- { name: admin1_name, type: text }
- { name: country_name, type: text }
- name: geocode_namedplace_point
return_type: Geometry
user_config_key: user_config
geocoder_config_key: geocoder_config
params:
- { name: city_name, type: text}
- name: geocode_namedplace_point
return_type: Geometry
user_config_key: user_config
geocoder_config_key: geocoder_config
params:
- { name: city_name, type: text}
- { name: country_name, type: text}
- name: geocode_namedplace_point
return_type: Geometry
user_config_key: user_config
geocoder_config_key: geocoder_config
params:
- { name: city_name, type: text}
- { name: admin1_name, type: text}
@ -36,18 +48,24 @@
- name: geocode_postalcode_polygon
return_type: Geometry
user_config_key: user_config
geocoder_config_key: geocoder_config
params:
- { name: postal_code, type: text}
- { name: country_name, type: text}
- name: geocode_postalcode_point
return_type: Geometry
user_config_key: user_config
geocoder_config_key: geocoder_config
params:
- { name: postal_code, type: text}
- { name: country_name, type: text}
- name: geocode_ipaddress_point
return_type: Geometry
user_config_key: user_config
geocoder_config_key: geocoder_config
params:
- { name: ip_address, type: text}

View File

@ -27,6 +27,14 @@ class SqlTemplateRenderer
@function_signature['return_type']
end
def user_config_key
@function_signature['user_config_key']
end
def geocoder_config_key
@function_signature['geocoder_config_key']
end
def params
@function_signature['params'].map { |p| p['name'] }.join(', ')
end