Skip to content

Instantly share code, notes, and snippets.

@rufuspollock
Created November 9, 2014 21:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rufuspollock/ca4ac7d2511ee41237b9 to your computer and use it in GitHub Desktop.
Save rufuspollock/ca4ac7d2511ee41237b9 to your computer and use it in GitHub Desktop.
CKAN DataStore SQL API from Javascript
// replace this with your CKAN website
var ckanSite = 'http://datahub.io'
var sql = 'Your SQL goes here';
// =================
// Using jQuery only
// =================
var data = encodeURIComponent(JSON.stringify({sql: sql}));
$.ajax({
url: ckanSite + '/api/3/action/datastore_search_sql',
type: 'POST',
dataType: 'json',
data: data,
success: function(data) { console.log(data) }
});
// ==============================================================
// Using ckan.js client library - https://github.com/okfn/ckan.js
// ==============================================================
var client = new CKAN.Client(ckanSite);
client.action('datastore_search_sql', {
sql: sql
},
function(err, out) {
if (err) console.log(err);
console.log(out);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment