| 1 | package SQL::Engine::Builder::Select; | ||
| 2 | |||
| 3 | use 5.014; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use registry; | ||
| 9 | use routines; | ||
| 10 | |||
| 11 | use Data::Object::Class; | ||
| 12 | use Data::Object::ClassHas; | ||
| 13 | |||
| 14 | extends 'SQL::Engine::Builder'; | ||
| 15 | |||
| 16 | use SQL::Validator; | ||
| 17 | |||
| 18 | our $VERSION = '0.01'; # VERSION | ||
| 19 | |||
| 20 | # ATTRIBUTES | ||
| 21 | |||
| 22 | has from => ( | ||
| 23 | is => 'ro', | ||
| 24 | isa => 'HashRef | ArrayRef[HashRef]', | ||
| 25 | req => 1 | ||
| 26 | ); | ||
| 27 | |||
| 28 | has columns => ( | ||
| 29 | is => 'ro', | ||
| 30 | isa => 'ArrayRef[Str | HashRef]', | ||
| 31 | new => 1 | ||
| 32 | ); | ||
| 33 | |||
| 34 | fun new_columns($self) { | ||
| 35 | [{ 'column' => '*' }] | ||
| 36 | } | ||
| 37 | |||
| 38 | has where => ( | ||
| 39 | is => 'ro', | ||
| 40 | isa => 'ArrayRef[HashRef]', | ||
| 41 | opt => 1 | ||
| 42 | ); | ||
| 43 | |||
| 44 | has joins => ( | ||
| 45 | is => 'ro', | ||
| 46 | isa => 'ArrayRef[HashRef]', | ||
| 47 | opt => 1 | ||
| 48 | ); | ||
| 49 | |||
| 50 | has group_by => ( | ||
| 51 | is => 'ro', | ||
| 52 | isa => 'ArrayRef[Str | HashRef]', | ||
| 53 | opt => 1 | ||
| 54 | ); | ||
| 55 | |||
| 56 | has having => ( | ||
| 57 | is => 'ro', | ||
| 58 | isa => 'ArrayRef[HashRef]', | ||
| 59 | opt => 1 | ||
| 60 | ); | ||
| 61 | |||
| 62 | has order_by => ( | ||
| 63 | is => 'ro', | ||
| 64 | isa => 'ArrayRef[HashRef]', | ||
| 65 | opt => 1 | ||
| 66 | ); | ||
| 67 | |||
| 68 | has rows => ( | ||
| 69 | is => 'ro', | ||
| 70 | isa => 'HashRef', | ||
| 71 | opt => 1 | ||
| 72 | ); | ||
| 73 | |||
| 74 | # METHODS | ||
| 75 | |||
| 76 | method data() { | ||
| 77 | my $schema = {}; | ||
| 78 | |||
| 79 | if ($self->from) { | ||
| 80 | $schema->{"from"} = $self->from; | ||
| 81 | } | ||
| 82 | |||
| 83 | if ($self->columns) { | ||
| 84 | $schema->{"columns"} = $self->columns; | ||
| 85 | } | ||
| 86 | |||
| 87 | if ($self->where) { | ||
| 88 | $schema->{"where"} = $self->where; | ||
| 89 | } | ||
| 90 | |||
| 91 | if ($self->joins) { | ||
| 92 | $schema->{"joins"} = $self->joins; | ||
| 93 | } | ||
| 94 | |||
| 95 | if ($self->group_by) { | ||
| 96 | $schema->{"group-by"} = $self->group_by; | ||
| 97 | } | ||
| 98 | |||
| 99 | if ($self->having) { | ||
| 100 | $schema->{"having"} = $self->having; | ||
| 101 | } | ||
| 102 | |||
| 103 | if ($self->order_by) { | ||
| 104 | $schema->{"order-by"} = $self->order_by; | ||
| 105 | } | ||
| 106 | |||
| 107 | if ($self->rows) { | ||
| 108 | $schema->{"rows"} = $self->rows; | ||
| 109 | } | ||
| 110 | |||
| 111 | return { | ||
| 112 | select => $schema | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | 1; |