# Pastebin 9n8LHDn2 raku -I. -MRed -MRed::Type -MRed::AST::Value -MJSON::Fast -MMoneys -e ' red-defaults "SQLite"; my $*RED-DEBUG = True; class DBMoney does Red::Type { method inflator { -> $_ is copy --> Money { given .&from-json { Money.new: :amount(.), :currency(.) } } } method deflator { -> Money $_ { to-json %( value => .amount, currency => .currency ) } } method red-type-column-type { "jsonb" } method red-type-accepts(Money) { True } method red-type-db-methods { role :: { method value { Red::AST::Cast.new: Red::AST::JsonItem.new(self, ast-value "amount"), "numeric" } method currency { Red::AST::Cast.new: Red::AST::JsonItem.new(self, ast-value "currency"), "text" } } } } model Transaction { has $.id is serial; has $.acc-from is column; has $.acc-to is column; has DBMoney $.value is column } schema(Transaction).create; Transaction.^create: :1acc-from, :2acc-to, :value(Money.new: :amount(9.99), :currency); .say for Transaction.^all.grep: *.value.currency eq "BRL" '