/
Select.pm6
53 lines (45 loc) · 1.17 KB
/
Select.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use Red::AST;
use Red::Model;
use Red::AST::Union;
use Red::AST::Intersect;
use Red::AST::Minus;
use Red::AST::Comment;
unit class Red::AST::Select does Red::AST;
has Mu:U $.of;
has Red::AST @.fields;
has Red::AST $.filter;
has Red::AST @.order;
has Int $.limit;
has Int $.offset;
has Red::AST @.group;
has @.table-list;
has Red::AST::Comment @.comments;
has Bool $.sub-select;
method returns { Red::Model }
method args { $!sub-select ?? () !! ( $!of, $!filter, |@!order ) }
method tables(::?CLASS:D:) {
|($!of, |@!table-list, |(.tables with $!filter), callsame).grep(-> \v { v !=:= Nil }).unique
}
method find-column-name {}
method union($sel) {
my $union = Red::AST::Union.new;
$union.union: self;
$union.union: $sel;
$union
}
method intersect($sel) {
my $union = Red::AST::Intersect.new;
$union.intersect: self;
$union.intersect: $sel;
$union
}
method minus($sel) {
my $union = Red::AST::Minus.new;
$union.minus: self;
$union.minus: $sel;
$union
}
method as-sub-select {
$!sub-select = True;
self;
}