# Pastebin R8J559ZF MacBook-Pro-de-Fernando:BestTree fernando$ cat Tree.pm6 use Red; class X::Tree::ExistsInTheSameArea is Exception { has Rat $.longitude; has Rat $.latitude; method message { "A tree on ($!longitude, $!latitude) was already suggested" } } model Tree { has UInt $!id is id; has Rat $.latitude is column; has Rat $.longitude is column; has Rat $.height is column; has Str $.description is column; ::?CLASS.^add-unique-constraint: { .latitude, .longitude }; method all-trees { self.^all.sort: -*.height } method find-tree(Rat $longitude, Rat $latitude) { self.^find: :$longitude, :$latitude } method suggest-tree(Rat $longitude, Rat $latitude, Rat $height, Str $description) { CATCH { when /"UNIQUE constraint failed"/ { die X::Tree::ExistsInTheSameArea.new: :$longitude, :$latitude } } self.^create: :$longitude, :$latitude, :$height, :$description } } MacBook-Pro-de-Fernando:BestTree fernando$ perl6 -I../Red2/lib/ -MRed -I. -MTree -e ' my $*RED-DB = database "SQLite"; Tree.^create-table; Tree.suggest-tree: 1.1, 2.2, 3.3, "bla"; Tree.suggest-tree: 1.1, 2.2, 3.4, "ble"; ' A tree on (1.1, 2.2) was already suggested in block at -e line 30 in method stt-exec at /Users/fernando/Documents/Projects/BestTree/../Red2/lib/Red/Driver/SQLite.pm6 (Red::Driver::SQLite) line 18 in method execute at /Users/fernando/Documents/Projects/BestTree/../Red2/lib/Red/Statement.pm6 (Red::Statement) line 13 in method execute at /Users/fernando/Documents/Projects/BestTree/../Red2/lib/Red/Driver.pm6 (Red::Driver) line 21 in method save at /Users/fernando/Documents/Projects/Red2/lib/MetamodelX/Red/Model.pm6 (MetamodelX::Red::Model) line 171 in method create at /Users/fernando/Documents/Projects/Red2/lib/MetamodelX/Red/Model.pm6 (MetamodelX::Red::Model) line 184 in method suggest-tree at -e line 33 in block at -e line 6