Skip to content

Instantly share code, notes, and snippets.

Last active December 2, 2018 03:18
What would you like to do?
use lib <lib>;
use Red;
model Person { ... }
model Wishlist {
has UInt $!id is id;
has UInt $!wisher-id is referencing{ };
has Person $.wisher is relationship{ .wisher-id };
has Str:D $.name is column is required;
has Str $.link is column;
model Person is rw {
has UInt $.id is id;
has Str $.name is column;
has Str $.email is column;
has UInt $!pair-id is referencing{ ::?CLASS.^ };
has ::?CLASS $.pair is relationship{ .pair-id };
has Wishlist @.wishes is relationship{ .wisher-id }
method draw(::?CLASS:U:) {
my @people = self.^all.pick: *;
for flat @people.rotor: 2 => -1 -> $p1, $p2 {
$p1.pair = $p2;
given @people.tail {
.pair = @people.head;
my $*RED-DB = database "SQLite";
my \fernando = Person.^create: :name<Fernando>, :email<>;
fernando.wishes.create: :name<Comma>, :link<>;
fernando.wishes.create: :name("perl6 books"), :link<>;
fernando.wishes.create: :name("mac book pro"), :link<>;
my \aline = Person.^create: :name<Aline>, :email<>;
aline.wishes.create: :name("a new closet"), :link<>;
my \fernanda = Person.^create: :name<Fernanda>, :email<>;
fernanda.wishes.create: :name("mimikyu plush"), :link<é-plush-%28standard-size%29---10-701-02831>;
fernanda.wishes.create: :name("camelia plush"), :link<>;
my \sophia = Person.^create: :name<Sophia>, :email<>;
sophia.wishes.create: :name("baby alive"), :link<>;
say "{ .name } -> { }\n\tWishlist: {*.name).join: ", " }" for Person.^all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment