Showing 25 changed files with 197 additions and 0 deletions
+2
t/common-mysql.t
... ...
@@ -20,6 +20,8 @@ use DBIx::Custom;
20 20
      . 'key3 varchar(255), key4 varchar(255), key5 varchar(255)) engine=InnoDB;' }
21 21
     sub create_table1_type { 'create table table1 (key1 Date, key2 datetime) engine=InnoDB;;' }
22 22
     sub create_table2 { 'create table table2 (key1 varchar(255), key3 varchar(255)) engine=InnoDB;' }
23
+    sub create_table2_2 { "create table table2 (key1 varchar(255), key2 varchar(255), key3 varchar(255)) engine=InnoDB" }
24
+    sub create_table3 { "create table table3 (key1 varchar(255), key2 varchar(255), key3 varchar(255)) engine=InnoDB" }
23 25
     sub create_table_reserved {
24 26
       'create table `table` (`select` varchar(255), `update` varchar(255)) engine=InnoDB;' }
25 27
 }
+2
t/common-postgresql.t
... ...
@@ -19,6 +19,8 @@ use DBIx::Custom;
19 19
      . 'key3 varchar(255), key4 varchar(255), key5 varchar(255));' }
20 20
     sub create_table1_type { 'create table table1 (key1 Date, key2 varchar(255));' }
21 21
     sub create_table2 { 'create table table2 (key1 varchar(255), key3 varchar(255));' }
22
+    sub create_table2_2 { "create table table2 (key1 varchar(255), key2 varchar(255), key3 varchar(255))" }
23
+    sub create_table3 { "create table table3 (key1 varchar(255), key2 varchar(255), key3 varchar(255))" }
22 24
     sub create_table_reserved { 'create table "table" ("select" varchar(255), "update" varchar(255))' }
23 25
 }
24 26
 
+2
t/common-sqlite-quote.t
... ...
@@ -14,6 +14,8 @@ use DBIx::Custom;
14 14
     sub create_table1_2 {'create table table1 (key1, key2, key3, key4, key5);' }
15 15
     sub create_table1_type { 'create table table1 (key1 Date, key2 datetime);' }
16 16
     sub create_table2 { 'create table table2 (key1, key3);' }
17
+    sub create_table2_2 { "create table table2 (key1, key2, key3)" }
18
+    sub create_table3 { "create table table3 (key1, key2, key3)" }
17 19
     sub create_table_reserved { 'create table "table" ("select", "update")' }
18 20
 }
19 21
 
+2
t/common-sqlite.t
... ...
@@ -13,6 +13,8 @@ use DBIx::Custom;
13 13
     sub create_table1_2 {'create table table1 (key1, key2, key3, key4, key5);' }
14 14
     sub create_table1_type { 'create table table1 (key1 Date, key2 datetime);' }
15 15
     sub create_table2 { 'create table table2 (key1, key3);' }
16
+    sub create_table2_2 { "create table table2 (key1, key2, key3)" }
17
+    sub create_table3 { "create table table3 (key1, key2, key3)" }
16 18
     sub create_table_reserved { 'create table "table" ("select", "update")' }
17 19
 }
18 20
 
+1
t/common.t
... ...
@@ -988,6 +988,7 @@ $dbi = DBIx::Custom->connect;
988 988
 eval { $dbi->execute("drop table ${q}table$p") };
989 989
 eval { $dbi->execute('drop table table1') };
990 990
 eval { $dbi->execute('drop table table2') };
991
+eval { $dbi->execute('drop table table3') };
991 992
 $dbi->execute($create_table1_type);
992 993
 $dbi->execute($create_table2);
993 994
 
+19
t/common/MyDBI1.pm
... ...
@@ -0,0 +1,19 @@
1
+package MyDBI1;
2
+
3
+use strict;
4
+use warnings;
5
+
6
+use base 'DBIx::Custom';
7
+
8
+sub connect {
9
+    my $self = shift->SUPER::connect(@_);
10
+    
11
+    $self->include_model(
12
+        MyModel1 => [
13
+            'book',
14
+            {class => 'Company', name => 'company'}
15
+        ]
16
+    );
17
+}
18
+
19
+1;
+17
t/common/MyModel1/Company.pm
... ...
@@ -0,0 +1,17 @@
1
+package MyModel1::Company;
2
+
3
+use strict;
4
+use warnings;
5
+
6
+use base 'DBIx::Custom::Model';
7
+
8
+
9
+sub insert {
10
+    my ($self, $param) = @_;
11
+    
12
+    return $self->SUPER::insert(param => $param);
13
+}
14
+
15
+sub list { shift->select; }
16
+
17
+1;
+13
t/common/MyModel1/book.pm
... ...
@@ -0,0 +1,13 @@
1
+package MyModel1::book;
2
+
3
+use DBIx::Custom::Model -base;
4
+
5
+sub insert {
6
+    my ($self, $param) = @_;
7
+    
8
+    return $self->SUPER::insert(param => $param);
9
+}
10
+
11
+sub list { shift->select; }
12
+
13
+1;
+5
t/common/MyModel4.pm
... ...
@@ -0,0 +1,5 @@
1
+package MyModel4;
2
+
3
+use base 'DBIx::Custom::Model';
4
+
5
+1;
+9
t/common/MyModel4/book.pm
... ...
@@ -0,0 +1,9 @@
1
+package MyModel4::book;
2
+
3
+use base 'MyModel4';
4
+
5
+sub table { 'table1' }
6
+
7
+sub list { shift->select }
8
+
9
+1;
+8
t/common/MyModel4/company.pm
... ...
@@ -0,0 +1,8 @@
1
+package MyModel4::company;
2
+
3
+use base 'MyModel4';
4
+
5
+sub insert { shift->SUPER::insert(param => $_[0]) }
6
+sub list { shift->select }
7
+
8
+1;
+5
t/common/MyModel5.pm
... ...
@@ -0,0 +1,5 @@
1
+package MyModel5;
2
+
3
+use base 'DBIx::Custom::Model';
4
+
5
+1;
+7
t/common/MyModel5/table1.pm
... ...
@@ -0,0 +1,7 @@
1
+package MyModel5::table1;
2
+
3
+use MyModel5 -base;
4
+
5
+has primary_key => sub { ['key1', 'key2'] };
6
+
7
+1;
+12
t/common/MyModel5/table1_1.pm
... ...
@@ -0,0 +1,12 @@
1
+package MyModel5::table1_1;
2
+
3
+use strict;
4
+use warnings;
5
+
6
+use base 'MyModel5';
7
+
8
+__PACKAGE__->attr(table => 'table2');
9
+
10
+__PACKAGE__->attr('primary_key' => sub { ['key1', 'key2'] });
11
+
12
+1;
+13
t/common/MyModel5/table1_2.pm
... ...
@@ -0,0 +1,13 @@
1
+package MyModel5::table1_2;
2
+
3
+use strict;
4
+use warnings;
5
+
6
+use base 'MyModel5';
7
+
8
+__PACKAGE__->attr(name => 'table1_3');
9
+__PACKAGE__->attr(table => 'table3');
10
+
11
+__PACKAGE__->attr('primary_key' => sub { ['key1', 'key2'] });
12
+
13
+1;
+5
t/common/MyModel6.pm
... ...
@@ -0,0 +1,5 @@
1
+package MyModel6;
2
+
3
+use base 'DBIx::Custom::Model';
4
+
5
+1;
+14
t/common/MyModel6/table1.pm
... ...
@@ -0,0 +1,14 @@
1
+package MyModel6::table1;
2
+
3
+use base 'MyModel6';
4
+
5
+__PACKAGE__->attr(
6
+    join => sub {
7
+        [
8
+            'left outer join table2 on table1.key1 = table2.key1'
9
+        ]
10
+    },
11
+    primary_key => sub { ['key1'] }
12
+);
13
+
14
+1;
+5
t/common/MyModel6/table2.pm
... ...
@@ -0,0 +1,5 @@
1
+package MyModel6::table2;
2
+
3
+use base 'MyModel6';
4
+
5
+1;
+11
t/common/MyModel6/table3.pm
... ...
@@ -0,0 +1,11 @@
1
+package MyModel6::table3;
2
+
3
+use base 'MyModel6';
4
+
5
+__PACKAGE__->attr(filter => sub {
6
+    [
7
+        key1 => {in => sub { uc $_[0] }}
8
+    ]
9
+});
10
+
11
+1;
+5
t/common/MyModel7.pm
... ...
@@ -0,0 +1,5 @@
1
+package MyModel7;
2
+
3
+use base 'DBIx::Custom::Model';
4
+
5
+1;
+14
t/common/MyModel7/table1.pm
... ...
@@ -0,0 +1,14 @@
1
+package MyModel7::table1;
2
+
3
+use base 'MyModel7';
4
+
5
+__PACKAGE__->attr(
6
+    primary_key => sub { ['key1'] },
7
+    join => sub {
8
+        [
9
+            'left outer join table2 on table1.key1 = table2.key1'
10
+        ]
11
+    },
12
+);
13
+
14
+1;
+5
t/common/MyModel7/table2.pm
... ...
@@ -0,0 +1,5 @@
1
+package MyModel7::table2;
2
+
3
+use base 'MyModel7';
4
+
5
+1;
+4
t/common/MyModel8.pm
... ...
@@ -0,0 +1,4 @@
1
+package MyModel8;
2
+use DBIx::Custom::Model -base;
3
+
4
+1;
+7
t/common/MyModel8/table1.pm
... ...
@@ -0,0 +1,7 @@
1
+package MyModel8::table1;
2
+use MyModel8 -base;
3
+
4
+has join => sub { ['left join table2 as table2_alias on table1.key1 = table2_alias.key1'] };
5
+
6
+
7
+1;
+10
t/common/MyModel8/table2.pm
... ...
@@ -0,0 +1,10 @@
1
+package MyModel8::table2;
2
+use MyModel8 -base;
3
+
4
+has filter => sub {
5
+    {
6
+        key3 => {out => sub { $_[0] * 2}, in => sub { $_[0] * 3}, end => sub { $_[0] * 4 }}
7
+    }
8
+};
9
+
10
+1;