dataservices-api/client/templates/20_public_functions.erb
2015-11-24 12:44:52 +01:00

24 lines
817 B
Plaintext

--
-- Public geocoder API function
--
-- These are the only ones with permissions to publicuser role
-- and should also be the only ones with SECURITY DEFINER
CREATE OR REPLACE FUNCTION <%= GEOCODER_CLIENT_SCHEMA %>.<%= name %> (<%= params_with_type %>)
RETURNS <%= return_type %> AS $$
DECLARE
ret <%= return_type %>;
user_config json;
geocoder_config json;
BEGIN
IF session_user = 'publicuser' THEN
RAISE EXCEPTION 'The api_key must be provided';
END IF;
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;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;