-
-
Notifications
You must be signed in to change notification settings - Fork 28
Features sample
Fernando Correa de Oliveira edited this page Sep 24, 2018
·
4 revisions
use Red;
my $*RED-DEBUG = True;
my $*RED-DB = database "SQLite";
model Bla {
has Int $.id is rw is column{:id, :!nullable};
has Int $.value is rw is column;
has Str $.name is rw is column;
}
Bla.^create-table;
my $a = Bla.^create: :1id, :42value;
Bla.^create: :2id, :42value, :name("the answer again");
$a.name = "the answer";
$a.^save;
say "===> ", Bla.^all
.grep({ .value == 42 })
.grep({ .id > 0 })
.sort(*.id)
.map({ .name })
.join: ", "
;
SQL : CREATE TABLE bla(
id integer NOT NULL primary key,
value integer NULL,
name varchar(255) NULL
)
SQL : INSERT INTO bla(
id,
value
)
VALUES(
1,
42
)
SQL : INSERT INTO bla(
id,
name,
value
)
VALUES(
2,
'the answer again',
42
)
SQL : UPDATE bla SET
name = 'the answer'
WHERE id = 1
SQL : SELECT
name as data
FROM
bla
WHERE
value = 42 AND id > 0
ORDER BY
id
===> the answer, the answer again