Skip to content

Conditional Logic Syntax

jfacorro edited this page Oct 30, 2014 · 3 revisions

Here's the definition of the syntax that sumo_db will support for the find_by/2 and delete_by/2 functions.

-type operator() :: '<' | '>' | '==' | '=<' | '>=' | '/=' | 'like'.
-type field_name() :: atom().
-type value() :: binary() | string() | number() | 'null' | 'not_null'.

-type expression() :: 
    [expression()] 
    | {'and', [expression()]} 
    | {'or', [expression()]} 
    | {'not', expression()}
    | terminal().

-type terminal() :: 
    {field_name(), operator(), field_name()} 
    | {field_name(), operator(), value()} 
    | {field_name(), value()}.

The expression [expression()] is equivalent to {and, [expression()]} for backwards compatibility. The following is an example of how a query expression would look like using this syntax:

{'or', [{'and', [{count, '<', 100}, 
                 {category, '==', "shoes"}]},
        {category, 'null'}
       ]
}.
Clone this wiki locally