# Pastebin 0Y60FiGe $ perl6 -MRed -e ' model Person { ... } model Track { has UInt $!id is serial; has UInt $!person-id is referencing{ Person.name }; has Person $.person is relationship{ .person-id }; has Instant $.time is column; } model Person { has Str $.name is id; has Track @.tracks is relationship{ .person-id } method total { @!tracks.sort(*.time).map(*.time).batch(2).map({ .[1] - .[0] }).sum } } my $*RED-DB = database "SQLite"; Person.^create-table; Track.^create-table; #my $*RED-DEBUG = True; my \fernando = Person.^create: :name; fernando.tracks.create: :time(now - 2000); fernando.tracks.create: :time(now - 1000); fernando.tracks.create: :time(now - 500); fernando.tracks.create: :time(now); say fernando.total ' 1500.021592308574