49
|
1 package Test::ORM::Schema;
|
|
2 use strict;
|
|
3 use warnings;
|
165
|
4 use parent qw(IMPL::Test::Unit);
|
49
|
5
|
|
6 require IMPL::SQL::Schema::Traits::mysql;
|
|
7
|
|
8 __PACKAGE__->PassThroughArgs;
|
|
9
|
|
10 use IMPL::Test qw(test failed);
|
|
11
|
|
12 require IMPL::ORM::Schema::TransformToSQL;
|
|
13
|
|
14 test ExtractClassSchema => sub {
|
|
15 my ($this) = @_;
|
|
16
|
|
17 my $schema = Test::ORM::Schema::Data::User->ormGetSchema('Test::ORM::Schema::Data');
|
|
18 failed "Wrong number of the elements","expected: 4","got: ".$schema->childNodes->Count unless $schema->childNodes->Count == 4;
|
|
19
|
|
20 return 1;
|
|
21 };
|
|
22
|
|
23 test StaticSchema => sub {
|
|
24 my ($this) = @_;
|
|
25
|
|
26 my $schema = Test::ORM::Schema::Data->instance;
|
|
27
|
|
28 return 1;
|
|
29 };
|
|
30
|
|
31 test GenerateSQL => sub {
|
|
32 my $sqlSchema = IMPL::ORM::Schema::TransformToSQL->Std->Transform(Test::ORM::Schema::Data->instance)
|
|
33 or failed("Failed to transform a schema");
|
|
34
|
|
35 my $sqlEmpty = new IMPL::SQL::Schema(Name => 'empty');
|
|
36
|
|
37 my $traits = IMPL::SQL::Schema::Traits::mysql->new(
|
|
38 SrcSchema => $sqlEmpty,
|
|
39 DstSchema => $sqlSchema
|
|
40 );
|
|
41
|
|
42 $traits->UpdateSchema();
|
|
43
|
|
44 print "$_\n" foreach $traits->Handler->Sql;
|
|
45
|
|
46 $sqlEmpty->Dispose;
|
|
47 $sqlSchema->Dispose;
|
|
48 };
|
|
49
|
|
50
|
|
51 package Test::ORM::Schema::Data::User;
|
165
|
52 use parent qw(IMPL::ORM::Object);
|
49
|
53 use IMPL::Class::Property;
|
|
54
|
|
55 BEGIN {
|
|
56 public property Name => prop_all, { type => 'String' }; # Field
|
|
57 public property Id => prop_all, { type => 'String' }; # Field
|
|
58 public property Roles => prop_all | prop_list, { type=> 'Test::ORM::Schema::Data::Role'}; # HasMany
|
|
59 }
|
|
60
|
|
61 package Test::ORM::Schema::Data::Role;
|
165
|
62 use parent qw(IMPL::ORM::Object);
|
49
|
63 use IMPL::Class::Property;
|
|
64
|
|
65 BEGIN {
|
|
66 public property Name => prop_all, { type => 'String' }; # Field
|
|
67 }
|
|
68
|
|
69 package Test::ORM::Schema::Data::Session;
|
165
|
70 use parent qw(IMPL::ORM::Object);
|
49
|
71 use IMPL::Class::Property;
|
|
72 use IMPL::ORM::Helpers qw(Map);
|
|
73
|
|
74 BEGIN {
|
|
75 public property Id => prop_get, { type => 'String' }; # Field
|
|
76 public property User => prop_get, { type => 'Test::ORM::Schema::Data::User' }; # HasOne
|
|
77 #public property Data => prop_all, { type => Map( 'String','String' ) }; # HasOne
|
|
78 public property AccessTime => prop_get, { type => 'DateTime' }; # Field
|
|
79 }
|
|
80
|
|
81 package Test::ORM::Schema::Data;
|
165
|
82 use parent qw(IMPL::ORM::Schema);
|
49
|
83
|
|
84 __PACKAGE__->ValueTypes (
|
|
85 String => 'IMPL::ORM::Value::String',
|
|
86 DateTime => 'IMPL::ORM::Value::DateTime',
|
|
87 Integer => 'IMPL::ORM::Value::Inetger',
|
|
88 Float => 'IMPL::ORM::Value::Float',
|
|
89 Decimal => 'IMPL::ORM::Value::Decimal'
|
|
90 );
|
|
91
|
|
92 __PACKAGE__->usePrefix(__PACKAGE__);
|
|
93 __PACKAGE__->Classes qw(
|
|
94 User
|
|
95 Role
|
|
96 Session
|
|
97 );
|
|
98
|
|
99 __PACKAGE__->CompleteSchema;
|
|
100
|
|
101 1;
|