-
Notifications
You must be signed in to change notification settings - Fork 2
/
13-roles.t
86 lines (62 loc) · 1.79 KB
/
13-roles.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use Test;
use Red;
use Red::Column;
my $*RED-DB = database "Mock";
my $*RED-DEBUG = $_ with %*ENV<RED_DEBUG>;
my $*RED-DEBUG-RESPONSE = $_ with %*ENV<RED_DEBUG_RESPONSE>;
$*RED-DB.die-on-unexpected;
role Bla { has Str $.a is column }
model Ble does Bla {}
$*RED-DB.when: :once, :return[], qq:to/EOSQL/;
CREATE TABLE ble(
a varchar(255) NOT NULL
)
EOSQL
Ble.^create-table;
model Bli does Bla { has Str $.b is column }
$*RED-DB.when: :once, :return[], qq:to/EOSQL/;
CREATE TABLE bli(
a varchar(255) NOT NULL,
b varchar(255) NOT NULL
)
EOSQL
Bli.^create-table;
$*RED-DB.when: :once, :return[{:1a}], "insert into ble ( a ) values ( ? )";
Ble.^create: :1a;
role SerialId {
has UInt $!id is serial;
}
model Blu { ... }
model Blo does SerialId {
has UInt $!blu-id is referencing{ Blu.id };
has Blu $.blu is relationship{ .blu-id };
}
model Blu does SerialId {
has Blo @.blo is relationship{ .blu-id };
}
$*RED-DB.when: :once, :return[], qq:to/EOSQL/;
create table blo (
blu_id integer null references blu (id),
id integer not null primary key autoincrement
)
EOSQL
$*RED-DB.when: :once, :return[], qq:to/EOSQL/;
create table blu (
id integer not null primary key autoincrement
)
EOSQL
Blo.^create-table;
Blu.^create-table;
$*RED-DB.when: :once, :return[{:1id}], "insert into blu default values";
$*RED-DB.when: :once, :return[{:1id, :1blu-id},], "insert into blo( blu_id )values( ? )";
my $blu = Blu.^create;
my $blo = $blu.blo.create;
$*RED-DB.when: :3times, :return[{:1id}], "select blu.id from blu where blu.id = ? limit 1";
isa-ok $blu, Blu;
isa-ok $blo, Blo;
is-deeply $blo.blu, $blu;
$*RED-DB.verify;
isa-ok Ble.a, Red::Column;
isa-ok Bli.a, Red::Column;
isa-ok Bli.b, Red::Column;
done-testing