A table in the tables
dir
create table parse.response
on select get from 'http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address={^address}'
using patch 'parse-response.js'
Patch in the same dir
// args.body would be an array of buffers
exports['parse response'] = function(args) {
return {
type: 'application/json',
content: JSON.stringify({
'name' : 'John Doe'
})
};
};
Try a select
select * from parse.response where address='foo'
This will return
{
"name": "John Doe"
}
The default implementation of the patch response
function is equivalent to the following
exports['parse response'] = function(args) {
var str = '';
_.each(args.body, function(buf) {
str += buf.toString('UTF-8');
});
return {
type: 'application/json',
content: str
};
}
I'm not sure if this is considered a bug or not but I've observed that if one attempts to place the script in the tables directory but define the table itself on the console that the following traceback is generated:
The workaround is to place the .ql and .js files in the tables directory, of course. It was just a wrinkle I wasn't expecting.