Last active
August 21, 2019 22:31
-
-
Save FCO/cc73863cf9058723176aa43781cb1f2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Red; | |
my $*RED-DB = database "SQLite"; | |
model Bla { ... } | |
model Ble { ... } | |
model Bli { ... } | |
model Bla { | |
has UInt $.id is serial; | |
has UInt $!ble-id is referencing( *.id, :model<Ble>); | |
has $.ble is relationship( *.ble-id, :model<Ble> ); | |
} | |
model Ble { | |
has UInt $.id is serial; | |
has UInt $!bli-id is referencing( *.id, :model<Bli> ); | |
has $.bli is relationship( *.bli-id, :model<Bli> ); | |
} | |
model Bli { | |
has UInt $.id is serial; | |
has Int $.value is column; | |
} | |
Bla.^create-table; Ble.^create-table; Bli.^create-table; | |
my $*RED-DEBUG = True; | |
say Bla.^all.grep: { .ble.bli.value == 42 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
bla.id , bla.ble_id as "ble-id" | |
FROM | |
bla | |
JOIN ble as bla_ble ON bla.ble_id = bla_ble.id | |
JOIN bli as bla_ble_bli ON bla_ble.bli_id = bla_ble_bli.id | |
WHERE | |
bla_ble_bli.value = 42 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment