Overview

About ql.io

Language Overview

Runtime Overview

Usage Overview

Getting Started

Prerequisites

Quick Start

Build an App

Examples

Build and Develop ql.io!

Writing Scripts

create table

connectors

select

if-else

insert

update

delete

URI Templates

Data Formats

Variable References

Configuration

Script Routes

Monkey Patching

UDF

try-catch-finally

Timeouts and Back-off

OAuth

Executing Scripts

HTTP Interface

WebSocket Interface

Engine API

Caching (Memcache)

Fallback

Conditions

Monitoring

Runtime Monitoring

References

Language Reference

URI Template Syntax Reference

Best Practices Guide

Troubleshooting

Examples

git clone git@github.com:ql-io/ql.io-site.git to see the scripts behind all the examples on this site.

List Tables

This statement lists all statically declared tables.

    show tables

Describe a Table

Describe a table. Comments before create table statements are used to generate HTML. Such comments can be Markdown formatted.

Try me
    describe eBay.ProductReviews

Select with Where

The conditions supplied in the where clause become inputs to HTTP request URIs, headers, or body.

Try me
select * from google.geocode where address = "bora bora"

Columns Clause for Projections

The columns clause is used to project the response to just the desired fields.

Try me
select ProductID[0].Value, DetailsURL, StockPhotoURL
  from eBay.FindProducts where QueryKeywords="mini cooper"

The result of a select with columns clause is an array of array of fields selected. Column names can use JSONPath format.

Columns Aliases

Column aliases change the format of the row in the results to be an object.

Try me
select ProductID[0].Value as id, DetailsURL as details, StockPhotoURL as photo
  from eBay.FindProducts where QueryKeywords="mini cooper"

Limit and Offset

You can paginate results by using limit and offset clauses.

Try me
select id as id, from_user_name as user, text as text
  from twitter.search where q = "ql.io" limit 5 offset 2

Dependencies

The second statement depends on the first statement via the variable reference {minis.itemId}.

Try me
minis = select * from finditems where keywords = 'mini cooper' limit 10;
return select PictureURL from details where itemId = "{minis.itemId}";

These statements will be executed in sequence due to the dependency of the second statement on the outcome of the first.

Nested Selection and Joins

See Quick Start Guide to construct this in steps.

Try me
select e.ItemID as id, e.Title as title, e.ViewItemURLForNaturalSearch as url, g.geometry.location as latlng
  from details  as e, google.geocode as g
  where e.itemId in (select itemId from finditems where keywords = "iPad")
        and g.address = e.Location

JSON

The right hand side of a variable assignment can also be an object.

Try me
foo = {
  "fname" : "Hello",
  "lname" : "World",
  "place" : "Sammamish, WA"};
data = select fname, lname, place from foo;
return {
  "data" :  "{data}"
};

In this example, the value foo is a JSON object. Here is another example that uses a JSONPath based selector.

Try me
    people = [
      {"fname" : "John", "lname" : "Doe"},
      {"fname" : "Jane", "lname" : "Doe"},
      {"fname" : "Joe", "lname" : "Developer"}];
    return "{people.$..fname}"

The selector in the return statement looks for all fname fields.

Insert

This examples uses insert into to shorten a URL via bitly APIs.

Try me
insert into bitly.shorten (longUrl) values ('http://ql.io/docs')

A select statement can be used to get the long form.

Try me
select long_url from bitly.shorten where shortUrl = 'http://bit.ly/uZIvmY'

Insert with parts

This examples uses insert into ... with parts to upload images to flickr

    insert into flickr.photos.upload with parts "{req.parts[0]}", "{req.parts[1]}"

SOAP

This example uses Bing's search API.

Try me
select * from bing.soap.search where q = "ql.io";

Mixing Twitter and Bing

This example uses Bing's search API.

Try me
keyword = "ql.io";
web = select * from bing.search where q = "{keyword}";
tweets = select id as id, from_user_name as user_name, text as text
  from twitter.search where q = "ql.io";

return {
  "keyword": "{keyword}",
  "web": "{web}",
  "tweets": "{tweets}"
}