### ----------------------------------------------------
### -- Red
### -- Licenses: Artistic-2.0
### -- Authors: Fernando Correa de Oliveira
### -- File: t/36-default-deflate.rakutest
### ----------------------------------------------------
#!/usr/bin/env raku
#
use Test;
use Red;

model Transaction is table<transactions> {
    has UInt        $.id            is serial;
    has Bool        $.closed        is column = False;
    has DateTime    $.date-time     is rw is column{ :nullable } .= now;
}

my $*RED-DEBUG          = $_ with %*ENV<RED_DEBUG>;
my $*RED-DEBUG-RESPONSE = $_ with %*ENV<RED_DEBUG_RESPONSE>;
my @conf                = (%*ENV<RED_DATABASE> // "SQLite").split(" ");
my $driver              = @conf.shift;
my $*RED-DB             = database $driver, |%( @conf.map: { do given .split: "=" { .[0] => val .[1] } } );

schema(Transaction).drop;

Transaction.^create-table;

Transaction.^create;
Transaction.^create: :closed;

is Transaction.^all.sort(*.id).Seq.map(*.closed), (False, True);
is Transaction.^all.sort(*.id).map(*.closed), (False, True);
is Transaction.^all.sort(*.id).map(!*.closed), (True, False);

lives-ok {
    my $t = Transaction.^create;
    $t.date-time = Nil;
    is $t.date-time, DateTime;
    $t.^save;
}

done-testing;


