{"body":" raku -I. -MRed -MRed::Type -MRed::AST::Value -MJSON::Fast -MMoneys -e '\nred-defaults \"SQLite\";\nmy $*RED-DEBUG = True;\n\n\nclass DBMoney does Red::Type {\n\n   method inflator { -> $_ is copy --> Money { given .&from-json { Money.new: :amount(.<value>), :currency(.<currency>) } } }\n   method deflator { -> Money $_ { to-json %( value => .amount, currency => .currency ) } }\n\n   method red-type-column-type { \"jsonb\" }\n   method red-type-accepts(Money) { True }\n   method red-type-db-methods {\n      role :: {\n         method value {\n            Red::AST::Cast.new: Red::AST::JsonItem.new(self, ast-value \"amount\"), \"numeric\"\n         }\n         method currency {\n            Red::AST::Cast.new: Red::AST::JsonItem.new(self, ast-value \"currency\"), \"text\"\n         }\n      }\n   }\n}\n\n\nmodel Transaction { has $.id is serial; has $.acc-from is column; has $.acc-to is column; has DBMoney $.value is column }\n\nschema(Transaction).create;\n\nTransaction.^create: :1acc-from, :2acc-to, :value(Money.new: :amount(9.99), :currency<BRL>);\n\n.say for Transaction.^all.grep: *.value.currency eq \"BRL\"\n\n'","name":"","extension":"txt","url":"https://www.irccloud.com/pastebin/9n8LHDn2","modified":1706396927,"id":"9n8LHDn2","size":1085,"lines":34,"own_paste":false,"theme":"","date":1706396927}