The Hooks Query Language is a simplified SQL-like language designed to retrieve items and apply filters over Hooks datasources.
- Selecting fields
- The FROM clause
- The WHERE clause
- The ORDER and GROUP BY clause
- HQL examples
Currently HQL only supports selecting all available item fields, and so, every query MUST begin with
SELECT *. Otherwise a parse error will be returned.
In HQL the
FROM clause references one datasource. This may also include a required parameter in form of a string or an entity subquery.
For example, SoccerGames datasource does not require parameter, so in order to fetch all current items the query would be like:
SELECT * FROM SoccerGames
However, if the datasource requires a string parameter as input, the statement would be:
SELECT * FROM RSS('theverge.com')
Alternatively, if the datasource requires an entity as mandatory parameter, this should be specified by including entity subquery
WHERE conditions within parenthesis.
SELECT * FROM WeatherByCity(name = 'Orihuela')
Note that HQL only supports fetching items from a single datasource, so if more than one is included in the
FROM clause a parse error will be returned.
The where clause allows you to refine the list of items returned from a datasouce.
SELECT * FROM SoccerGames WHERE home_team.team_name = 'Real Madrid'
This returns all items contained in SoccerGames where home team is
Expressions used in the where clause include the following:
- binary comparison operators: =, >=, <=, <>, !=, like
- logical operations
- Parentheses ( ) that indicates grouping
IS NOT NULL
GROUP BY clauses and not currently supported in HQL.
The following queries show the power of HQL put in practice, though maybe most of the ones you will write will be much simpler than the following examples.
This example will return all those matches in which
Real Madrid played and won.
SELECT * FROM SoccerGames WHERE ( (home_team.team_name = 'Real Madrid' AND home_score > away_score) OR (away_team.team_name = 'Real Madrid' AND away_score > home_score) ) AND status = 'FINAL'
Here’s a another one that will return of those items from a parametrized RSS datasource that contains the sentence ‘machine learning’.
SELECT * FROM RSS('theverge.com') WHERE content LIKE '%marchine learning%'