default_value might also be a ScalarRef
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Column.pm
CommitLineData
4f4fd192 1use MooseX::Declare;
ebf2721d 2class SQL::Translator::Object::Column extends SQL::Translator::Object {
1ddd6d2a 3 use MooseX::Types::Moose qw(Bool Int Maybe ScalarRef Str);
f49a2a49 4 use MooseX::MultiMethods;
ada068ed 5 use SQL::Translator::Types qw(Bit ColumnSize Constraint Table Trigger);
f49a2a49 6
7 has 'table' => (
8 is => 'rw',
9 isa => Table,
10 required => 1,
11 weak_ref => 1,
12 );
4f4fd192 13
14 has 'name' => (
15 is => 'rw',
16 isa => Str,
17 required => 1
18 );
19
20 has 'data_type' => (
21 is => 'rw',
81429cb9 22 isa => Str,
23 required => 1
24 );
25
26 has 'sql_data_type' => (
27 is => 'rw',
4f4fd192 28 isa => Int,
29 required => 1
30 );
31
32 has 'size' => (
33 is => 'rw',
70ada8ac 34 isa => ColumnSize,
35 coerce => 1,
36 auto_deref => 1,
4f4fd192 37 );
38
39 has 'is_nullable' => (
40 is => 'rw',
41 isa => Bool,
42 required => 1,
43 default => 1
44 );
45
4f4fd192 46 has 'default_value' => (
47 is => 'rw',
1ddd6d2a 48 isa => Maybe[ScalarRef|Str],
4f4fd192 49 );
0874db2d 50
81429cb9 51 has 'is_auto_increment' => (
52 is => 'rw',
ada068ed 53 isa => Bit,
81429cb9 54 required => 1,
ada068ed 55 coerce => 1,
81429cb9 56 default => 0
57 );
58
0874db2d 59 has 'is_primary_key' => (
60 is => 'rw',
61 isa => Bool,
62 default => 0
63 );
70ada8ac 64
65 has 'is_foreign_key' => (
66 is => 'rw',
67 isa => Bool,
68 default => 0
69 );
70
71 has 'foreign_key_reference' => (
72 is => 'rw',
73 isa => Constraint,
74 );
4f4fd192 75
76 has 'trigger' => (
77 is => 'rw',
78 isa => Trigger,
79 );
0874db2d 80
70ada8ac 81 around size(@args) {
82 $self->$orig(@args) if @args;
83 my @sizes = $self->$orig;
84 return wantarray ? @sizes
85 : join ',', @sizes;
86 }
b750d2f1 87
88 method order { }
89 method is_unique { }
4f4fd192 90}