Skip to content

Commit

Permalink
Revert "Make Red::Type be able to add methods on column"
Browse files Browse the repository at this point in the history
This reverts commit 2b25a9d.
  • Loading branch information
FCO committed Jan 11, 2023
1 parent 6d18bcf commit 19c73c8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 27 deletions.
3 changes: 0 additions & 3 deletions lib/Red/Column.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@ method as(Str $name, :$nullable = True) {
}

submethod TWEAK(:$unique) {
if $!attr.type.^find_method: "red-type-db-methods" {
self does $!attr.type.red-type-db-methods
}
with $unique {
when Bool {
$!attr.package.^add-unique-constraint: { self }
Expand Down
11 changes: 0 additions & 11 deletions lib/Red/Driver/Pg.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,6 @@ multi method translate(Red::AST::Cast $_ where { .type eq "boolean" && .value.?r
self.translate: Red::AST::IsDefined.new: .value;
}

multi method translate(Red::AST::Cast $_, $context?) {
when Red::AST::Value {
.bind ?? self.translate(.value, "bind") !! qq|'{ .value }'| => []
}
default {
my ($str, @bind) := do given self.translate: .value, .bind ?? "bind" !! $context { .key, .value }
"({ $str })::{ .type }" => @bind
}
}


multi method translate(Red::Column $_, "column-auto-increment") {}

multi method translate(Red::AST::Select $_, $context?, :$gambi where !*.defined) {
Expand Down
16 changes: 3 additions & 13 deletions t/75-red-type.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
use Test;
use Red;
use Red::Type;
use Red::AST::Value;
use Red::AST::Unary;

my $*RED-FALLBACK = False;
my $*RED-DEBUG = $_ with %*ENV<RED_DEBUG>;
Expand All @@ -20,19 +18,13 @@ class Point {

class DBPoint does Red::Type {
method inflator {
-> $_ --> Point { Point.new: :x(.<x>), :y(.<y>) }
-> Str $_ --> Point { do given .split: "," -> ($x, $y) { Point.new: :$x, :$y } }
}
method deflator {
-> Point $_ { %( :x(.x), :y(.y) ) }
-> Point $_ --> Str { "{.x},{.y}" }
}
method red-type-column-type { "jsonb" }
method red-type-column-type { "string" }
method red-type-accepts(Point) { True }
method red-type-db-methods {
role :: {
method x { Red::AST::Cast.new: Red::AST::JsonItem.new(self, ast-value "x"), "integer" }
method y { Red::AST::Cast.new: Red::AST::JsonItem.new(self, ast-value "y"), "integer" }
}
}
}

model Place {
Expand All @@ -50,6 +42,4 @@ isa-ok $p.point, Point;
is $p.point.x, 0;
is $p.point.y, 10;

.say for Place.^all.grep: *.point.x >= 0;

done-testing

0 comments on commit 19c73c8

Please sign in to comment.