From e148448bcd29f241f1d47724de3326ce73e4d183 Mon Sep 17 00:00:00 2001 From: Dominik Moritz Date: Mon, 27 Aug 2012 14:32:13 +0100 Subject: [PATCH] Added the data_search_sql action --- ckanext/datastore/logic/action.py | 29 +++++++++++++++++++++++++++++ ckanext/datastore/plugin.py | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ckanext/datastore/logic/action.py b/ckanext/datastore/logic/action.py index 489a954e8ec..99c7f99e37f 100644 --- a/ckanext/datastore/logic/action.py +++ b/ckanext/datastore/logic/action.py @@ -118,3 +118,32 @@ def datastore_search(context, data_dict): result.pop('id', None) result.pop('connection_url') return result + +@logic.side_effect_free +def data_search_sql(context, data_dict): + '''Execute SQL-Queries on the datastore. + + :param sql: a single sql select statement + + :returns: a dictionary containing the search parameters and the + search results. + keys: fields: same as datastore_create accepts + offset: query offset value + limit: query limit value + filters: query filters + total: number of total matching records + records: list of matching results + :rtype: dictionary + + ''' + model = _get_or_bust(context, 'model') + sql = _get_or_bust(data_dict, 'sql') + + p.toolkit.check_access('datastore_search', context, data_dict) + + data_dict['connection_url'] = pylons.config['ckan.datastore_read_url'] + + result = db.search_sql(context, data_dict) + result.pop('id', None) + result.pop('connection_url') + return result diff --git a/ckanext/datastore/plugin.py b/ckanext/datastore/plugin.py index 2a9e4f32e6a..e60e2baa113 100644 --- a/ckanext/datastore/plugin.py +++ b/ckanext/datastore/plugin.py @@ -60,7 +60,8 @@ def new_resource_show(context, data_dict): def get_actions(self): return {'datastore_create': action.datastore_create, 'datastore_delete': action.datastore_delete, - 'datastore_search': action.datastore_search} + 'datastore_search': action.datastore_search, + 'data_search_sql': action.data_search_sql} def get_auth_functions(self): return {'datastore_create': auth.datastore_create,