Espresso++ is a natural query language that abstracts away the native query language of any data management system. Espresso++ aims to provide API users with a powerful yet very simple query mechanism, that hides type and schema of the underlying database. Last but not least, Espresso++ is designed with security in mind to prevent any kind of cyber-attack like code-injection.
Syntax is how a statement is worded and structured. It is the study of the principles and processes by which statements are constructed in Espresso++.
The first version of Espresso++ supports logical and matching operators as well as
a number of helpful macros. A record is selected when the filtering expression evaluates
to true
— an expression is a combination of one or more constants, fields, operators,
and macros that Espresso++ interprets and computes to produce a native query.
Logical operators allow a program to make a decision based on multiple conditions.
Each expression is considered a condition that can be evaluated to true
or false
.
Operator | Usage | Description |
---|---|---|
|
expr1 |
Evaluates to |
|
expr1 |
Evaluates to |
|
|
Evaluates to |
Matching operators allow a program to compare two expressions or determine whether an
expression matches a given condition. Matching conditions can be evaluated to true
or
false
.
Operator |
Usage |
Description |
|
expr1 |
Evaluates to |
|
expr1 |
Evaluates to |
|
expr |
Evaluates to |
|
expr1 |
Evaluates to |
|
expr1 |
Evaluates to |
|
expr1 |
Evaluates to |
|
expr1 |
Evaluates to |
|
expr1 |
Evaluates to |
|
expr1 |
Evaluates to |
|
expr1 |
Evaluates to |
|
expr1 |
Evaluates to |
Macros are single instructions that expand automatically into a set of instructions.
Macro | Arguments | Description |
---|---|---|
|
Expands to current time |
|
|
Duration in ISO-8601 format |
Expands to a duration in milliseconds |
Finally, Espresso++ supports basic mathematics that allow complex expressions.
Math | Usage | Description |
---|---|---|
|
expr1 |
Adds up an expression with another |
|
expr1 |
Subtracts an expression from another |
|
expr1 |
Multiplies an expression by another |
|
expr1 |
Divides an expression by another |
Grammar is the set of structural rules that govern the composition of statements in Espresso++, and Extended Backus-Naur Form 2 (EBNF2) is the formalism (or metalanguage) used to describe it.
digit = . // https://golang.org/ref/spec#decimal_digit
identifier = . // https://golang.org/ref/spec#identifier
int = . // https://golang.org/ref/spec#int_lit
float = . // https://golang.org/ref/spec#float_lit
string = . // https://golang.org/ref/spec#string_lit
bool = "true" | "false" .
date = digit digit digit digit "-" digit digit "-" digit digit .
time = digit digit ":" digit digit ":" digit digit [ "." { digit } ] .
Query = Expression { Expression } .
Expression = "and" | "or"
| SubExpression
| Comparison
| Equality
| Match
| Range
| Is .
SubExpression = [ "not" ] "(" Expression { Espression } ")" .
Date = "\"" date "\"" | "'" date "'" .
Time = "\"" time "\"" | "'" time "'" .
DateTime = "\"" date "T" time [ "+" digit digit ] "\""
| "'" date "T" time [ "+" digit digit ] "'" .
Term = identifier
| int | float | string | bool
| Date | Time | DateTime
| Macro .
Macro = "#" identifier [ "(" Term { "," Term } ")" ] .
Math = Term ( "add" | "sub" | "mul" | "div" ) Term .
TermOrMath = ( Math | "(" Math ")" | Term ) .
Comparison = TermOrMath ( "gt" | "gte" | "lt" | "lte" ) TermOrMath.
Equality = TermOrMath ( "eq" | "neq" ) TermOrMath .
Match = Term ( "startswith" | "endswith" | "contains" ) Term .
Range = TermOrMath "between" TermOrMath "and" TermOrMath .
Is = identifier "is" [ "not" ] bool
| "is" [ "not "] identifier
| identifier "is" [ "not" ] "null" .
This article ends with some examples that show Espresso++ in action.
Select the persons with surname Walker and name starting with J:
surname eq "Walker" and name startswith "J"
Select the persons who are between 20 and 40 years old:
age between 20 and 40
Select the orders with at least 2000 items that have been created in the past 2 hours:
size gte 2000 and not(create_time lt #now sub #duration("PT2H"))
Select internal orders issued by employee 110110:
employee_id eq 110110 and internal is true
Or alternatively:
employee_id eq 110110 and is internal
Select the orders with customer notes:
customer_note is not null
Copyright © 2020 Skeeter Health