Skip to content

Commit

Permalink
Added the data_search_sql action
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Aug 27, 2012
1 parent 35eef77 commit e148448
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
29 changes: 29 additions & 0 deletions ckanext/datastore/logic/action.py
Expand Up @@ -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
3 changes: 2 additions & 1 deletion ckanext/datastore/plugin.py
Expand Up @@ -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,
Expand Down

0 comments on commit e148448

Please sign in to comment.