Help language development. Donate to The Perl Foundation

Red cpan:FCO last updated on 2020-07-23

use Test;
use Red;

plan 1;

my $*RED-DB = database "Mock";

model M is table<mmm> {
    has Int     $.a is column;
    has Bool    $.b is column;



$*RED-DB.when: :twice, Q[select case when ( mmm.b == 0 or mmm.b is null ) then mmm.a else mmm.b end as "data_1" from mmm], :return[{:1data_1}, {:2data_1}, {:3data_1}];
$*RED-DB.when: :once,  Q[select mmm.a as "data_1" from mmm], :return[{:1data_1}, {:2data_1}, {:3data_1}];

M.^{ .b ?? .b !! .a }).Seq.head;

M.^{ .b || .a }).Seq.head;

M.^{ .b if .b; .a }).Seq.head;

$*RED-DB.when: :once, rx[select <.ws> [ "mmm."[a|b] <.ws> as <.ws> \"data_\d\" ] ** 3 % [<.ws>","<.ws>] <.ws> from <.ws> mmm], :return[{:1data_1}, {:2data_1}, {:3data_1}];

M.^{ .a, .b, .a }).Seq.head;

#$*RED-DB.when: #`(:twice) :once, Q[SELECT mmm.a as "data" FROM mmm WHERE not (b == 0 OR b IS NULL)], :return[{:1data}, {:2data}, {:3data}];
#M.^{ .a if .b }).Seq;
##M.^{ next unless .b; .a }).Seq; # TODO: review next