Skip to content

Latest commit

History

18 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

simple user query language

suql is a small language for writing simple data queries. The intended use case is to give users of a web application the ability to perform predicate-based filtering on a table, similar to JQL for JIRA. suql has an interpreter that lets it query collections of Scala objects, and also a compiler that converts the suql code to a SQL or MongoDB query.

Language features

  • Everything is an expression, and a query is a single expression
  • Equality and order comparisons (=, !=, >, <)
  • Logical negation (!) and boolean operators (&&, ||)

The language deliberately omits a few features to maximise security, simplicity and portability.

  • No variables
  • No user-defined functions
  • No ability to assign, write or update data - purely read-only

An example: querying countries

Let's say we have a table of countries, like so:

country.namecountry.continentcountry.population
United KingdomEurope64100000
FranceEurope66030000
United StatesNorth America316500000
.........

If we want to query all of the countries in Europe - the query would look like this:

country.continent = "Europe"

Boolean logic allows us to write more complicated queries, like this:

country.continent = "North America" && country.population > 100000000

Parentheses can be used to disambiguate expressions:

(country.continent = "North America") && (country.population > 100000000)

This example shows how to perform a query from Scala code:

caseclassCountry(name: String, continent: String, population: Int)
valcountries=List(
Country("United Kingdom", "Europe", 64100000),
Country("France", "Europe", 66030000),
Country("United States", "North America", 316500000)
)
valcollectionQuery:CollectionQuery=newCollectionQueryvalbigCountriesInNorthAmerica= collectionQuery.query("country.continent = \"North America\" && country.population > 100000000", testCountries)

Adding targets

To write a new code generation target, implement the CodeGenerator trait. An example, which turns a suql syntax tree back into suql code, is implemented in the Uncompiler class.

About

A data query language which can be used for filtering Scala collections or translated to SQL.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages