Skip to content

Instantly share code, notes, and snippets.

@FCO
Last active November 27, 2018 03:15
Show Gist options
  • Save FCO/87831dd190e1bb12adb138ce866acb73 to your computer and use it in GitHub Desktop.
Save FCO/87831dd190e1bb12adb138ce866acb73 to your computer and use it in GitHub Desktop.
Red ORM conditionals optimizations

Starting to write some optimization on conditionals:

use Red;

model M is table<mmm> {
   has Str $.a is column;
   has Int $.b is column;
   has Str $.c is column;
   has Str $.d is column;
}
my $*RED-DB = database "SQLite";
M.^create-table;

say M.^all.map: { .b < 10 ?? .b > 2 ?? .a !! .c !! .d }

Is running the SQL:

SELECT
   CASE 
      WHEN b > 2 AND b < 10 THEN a
      WHEN b <= 2 THEN c
      WHEN b >= 10 THEN d
   END
    as "data"
FROM
   mmm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment