1. ql.io and Node.js: Next Generation
Open Source Web Querying System
Jonathan LeBlanc
Developer Evangelist: X.commerce
Email: jleblanc@x.com
Twitter: @jcleblanc
Github: github.com/jcleblanc
2. Topics We’ll Be Covering
Overview of ql.io
Language Specifications
Monkey Patching & Enhancements
Integrating Into Your Node Applications
Tools and More
3. Topics We’ll Be Covering
Overview of ql.io
Language Specifications
Monkey Patching & Enhancements
Integrating Into Your Node Applications
Tools and More
12. ql.io: Using the Standalone Server
Data
(internal)
ql.io Node Host
Data
(external)
13. Topics We’ll Be Covering
Overview of ql.io
Language Specifications
Monkey Patching & Enhancements
Integrating Into Your Node Applications
Tools and More
15. Language: Create Table for Data Source
create table TABLE_NAME
on select get from "http://api.com/?val1={val1}"
using defaults val1="VALUE",
val2="VALUE”;
16. Language: Sample Github Issues Table
create table github.issues
on select get from "https://github.com/api/v2/json/
issues/list/{user}/{repository}/
{state}/"
using defaults state="open";
17. Language: Obtain Data From New Tables
select * from TABLE_NAME
where val1="VALUE"
and val2="VALUE"
limit 10
offset 3;
20. Language: Nested Selects
select ItemID, ViewItemURLForNaturalSearch, Location
from details
where itemId
in (select itemId
from finditems
where keywords='mini cooper');
[
"330730216553",
"http://www.ebay.com/itm/Clubman-Auto-Sunroof-Prem-…",
"Huntingdon Valley, Pennsylvania"
],
22. Language: Including Script Routes
user = "jcleblanc";
slides = select * from slideshare where user="{user}";
twitter = select * from github.users where user="{user}";
return {
"slides": "{slides}",
"twitter": "{twitter}"
}
via route '/social' using method post;
24. Topics We’ll Be Covering
Overview of ql.io
Language Specifications
Monkey Patching & Enhancements
Integrating Into Your Node Applications
Tools and More
25. Patching: Including the Monkey Patch
create table TABLE_NAME
on select get from "http://api.com/?val1={val1}"
using defaults val1="VALUE"
using patch "patch.js";
27. Patching: The Body Patch
exports['patch body'] = function() {
return {
type: 'application/json',
content: JSON.stringify({message : 'aok'})
};
}
28. Patching: The Response Patch
exports['patch response'] = function(args){
var body = args.body;
//modify response body
return body;
}
29. Topics We’ll Be Covering
Overview of ql.io
Language Specifications
Monkey Patching & Enhancements
Integrating Into Your Node Applications
Tools and More
33. Topics We’ll Be Covering
Overview of ql.io
Language Specifications
Monkey Patching & Enhancements
Integrating Into Your Node Applications
Tools and More
35. Tools: API Masher
var format = “<li><a href=‘{{link}}’ target=‘_blank’>
<img src=‘{{media:content.media:thumbnail.url}}’
width=‘{{media:content.media:thumbnail.width}}’
height=‘{{media:content.media:thumbnail.height}}’ /></a>
<br /><span class=‘small’>
<a href=‘{{link}}’ target=‘_blank’>{{title}}</a></span></li>”;
36. Tools: API Masher
var query = “create table slideshare
on select get from ‘http://www.slideshare.net/rss/user/{user}’
resultset ‘rss.channel’;
select * from slideshare where user=“jcleblanc”
var insertEl = “widgetContainer”;
parser.push(query, format, insertEl);
parser.render();
Mashing up multiple data sourcesPerformance issuesAdd slides showing performance hits
Most mobile applications will, on average, make at least 5+ HTTP data requests per UI paint.
Language based on a SQL-like syntax which exports all data to JSON
If you’re using the web endpoint you would make HTTP GET requests to the API endpoint, inserting your query in the request. A JSON response will be returned to you.
If you download the standalone server version of ql.io, it will sit on top of your existing node server (or within your node applications) and be able to query your internal data and/or external data sources
A create table call (to define a data source) may be included in the HTTP request to the ql.io web source or defined in a .ql file, which is added into the /tables directory of your application.
Update / Delete requests not currently supported, but are being actively worked on.
create table slideshare on select get from "http://www.slideshare.net/rss/user/{user}" resultset "rss.channel";create table github.users on select get from "http://github.com/api/v2/json/user/show/{user}";user = "jcleblanc";slides = select * from slideshare where user="{user}";twitter = select * from github.users where user="{user}";return { "slides": "{slides}", "twitter": "{twitter}"}
Route files are also stored with the .ql extension but are placed under the routes directory
var script = "create table geocoder " + " on select get from 'http://maps.googleapis.com/maps/api/geocode/json?address={address}&sensor=true' " + " resultset 'results.geometry.location'" + "select lat as lattitude, lng as longitude from geocoder where address='Mt. Everest'";engine.execute(script, function(emitter) {emitter.on('end', function(err, res) {console.log(res.body[0]); });});
var script = "create table geocoder " + " on select get from 'http://maps.googleapis.com/maps/api/geocode/json?address={address}&sensor=true' " + " resultset 'results.geometry.location'" + "select lat as lattitude, lng as longitude from geocoder where address='Mt. Everest'";engine.execute(script, function(emitter) {emitter.on('end', function(err, res) {console.log(res.body[0]); });});