Created
November 9, 2014 21:37
-
-
Save rufuspollock/ca4ac7d2511ee41237b9 to your computer and use it in GitHub Desktop.
CKAN DataStore SQL API from Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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