| 1 | package SQL::Engine::Builder::ConstraintCreate; | ||
| 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.02'; # VERSION | ||
| 19 | |||
| 20 | # ATTRIBUTES | ||
| 21 | |||
| 22 | has name => ( | ||
| 23 | is => 'ro', | ||
| 24 | isa => 'Str', | ||
| 25 | opt => 1 | ||
| 26 | ); | ||
| 27 | |||
| 28 | has on => ( | ||
| 29 | is => 'ro', | ||
| 30 | isa => 'HashRef', | ||
| 31 | opt => 1 | ||
| 32 | ); | ||
| 33 | |||
| 34 | has source => ( | ||
| 35 | is => 'ro', | ||
| 36 | isa => 'HashRef', | ||
| 37 | req => 1 | ||
| 38 | ); | ||
| 39 | |||
| 40 | has target => ( | ||
| 41 | is => 'ro', | ||
| 42 | isa => 'HashRef', | ||
| 43 | req => 1 | ||
| 44 | ); | ||
| 45 | |||
| 46 | has safe => ( | ||
| 47 | is => 'ro', | ||
| 48 | isa => 'Bool', | ||
| 49 | opt => 1 | ||
| 50 | ); | ||
| 51 | |||
| 52 | # METHODS | ||
| 53 | |||
| 54 | method data() { | ||
| 55 | my $schema = {}; | ||
| 56 | |||
| 57 | if ($self->name) { | ||
| 58 | $schema->{"name"} = $self->name; | ||
| 59 | } | ||
| 60 | |||
| 61 | if ($self->on) { | ||
| 62 | $schema->{"on"} = $self->on; | ||
| 63 | } | ||
| 64 | |||
| 65 | if ($self->source) { | ||
| 66 | $schema->{"source"} = $self->source; | ||
| 67 | } | ||
| 68 | |||
| 69 | if ($self->target) { | ||
| 70 | $schema->{"target"} = $self->target; | ||
| 71 | } | ||
| 72 | |||
| 73 | if ($self->safe) { | ||
| 74 | $schema->{"safe"} = $self->safe; | ||
| 75 | } | ||
| 76 | |||
| 77 | return { | ||
| 78 | "constraint-create" => $schema | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | 1; |