Snippets

chromawallet Any queries

Created by Riccardo Sibani
So we want to allow complex - dynamic queries in rell.

Let's say that there is an entity like such:

entity character {
  name;
  color;
  age: integer;
  height: integer;
  weight: integer;
}

We want user to be able to filter by none / some / all those parameters both with inclusive and / or exclusive clauses.

E.g

* I want to get the characters whose color is not black
* I want to get the characters whose color is not black and age is higher than 18


One exclusive clause can always be converted into an inclusive clause.

i.e.
* I dont' want it black = I want it orange, red, green (all the colors but black)


Example query

query filterCharacter(name, colors: set<color>, ageIntervals: list<(integer, integer)>, heightIntervals: list<(integer, integer)>, weightIntervals: list<(integer, integer) ) {
  return character@*{
    name,
    color: any(colors),
    age: not all(ageIntervals)
    height: height
  }
}

exact             |  height 
one among the     |  set<height>  | @heights
                                                              all               |  set<height>  | @*heights
none              |  set<height>  | not @heights




enum color {
  black,
  white
}
val maxHeight = 200;
// || val maxHeight = Integer.MAX_VALUE;

val allowedAges = set<integer>(18, 21, 65);

alias int_interval {
  minVal: integer,
  maxVal: integer
}

function filterCharacterByAllProperties(height: set<int_interval>, color = color.*) {
  characters@*{
    height <= maxHeight,
    height >= minHeight,

    // only allow 18, 21, 65
    age = @allowedAges, 

    // not allow 18, 21, 65
    age = not @allowedAges

    height = ]18,65[,
    height = [18, 65[, ]73, 94],

    color = (color.* || color.white || color.black),
  }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.