Skip to content

Instantly share code, notes, and snippets.

@s3u
Created April 24, 2012 03:32
Show Gist options
  • Save s3u/2476192 to your computer and use it in GitHub Desktop.
Save s3u/2476192 to your computer and use it in GitHub Desktop.

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
    };
}
@s3u
Copy link
Author

s3u commented Jun 22, 2012

Actually, the console is supposed to warn that the patch is not locatable in this case. See ql-io/ql.io#417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment