Skip to content

SyntaxLiterals

Glythcing edited this page Sep 17, 2018 · 2 revisions

Tranquil supports string and numeric literals.

String Literals

String literals are denoted by opening and closing single quotes: '. They can be used ...

  • As the RHS operand in a predicate, for example: a = 'foo'
  • In a projection, for example 'foo' or, using an alias, 'foo' as notFoo

In projections, string literals can be concatenated using the + operator. Given this JSON:

{
  "name": "glytching"
}

This projection:

name, 'foo_' + name as fooName`

Will return:

{
  "name": "glytching",
  "fooName": "foo_glytching"
}

Numeric Literals

Numeric literals are literal values which are not string quoted and are coercible to a number. They can be used ...

  • As the RHS operand in a predicate, for example: a = 2
  • In a projection, for example 10 or, using an alias, 10 as ten

In projections, numeric literals can be used along with arithmetic operators to transform an input. Given this JSON:

{
  "count": 10
}

This projection:

count, 
5 + count as fivePlusCount, 
40 - count as fortyMinusCount, 
2 * count as doubleCount, 
20 / count and twentyDividedByCount

Will return:

{
  "count": 10,
  "fivePlusCount": 15,
  "fortyMinusCount": 30,
  "doubleCount": 20,
  "twentyDividedByCount": 2
}