Showing 3 changed files with 113 additions and 50 deletions
+1
Changes
... ...
@@ -1,6 +1,7 @@
1 1
 0.1712
2 2
     - you can set any string as separator
3 3
     - fixed memory leak and connection increasing bug, and query_buider method return new object.
4
+    - added EXPERIMENTAL system_table attribute
4 5
 0.1711
5 6
     - renamed EXPERIMENTAL available_type_name to available_typename
6 7
     - renamed EXPERIMENTAL available_data_type to available_datatype
+81 -50
lib/DBIx/Custom.pm
... ...
@@ -19,7 +19,7 @@ use Encode qw/encode encode_utf8 decode_utf8/;
19 19
 use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0;
20 20
 use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8';
21 21
 
22
-has [qw/connector dsn password quote user/],
22
+has [qw/connector dsn password quote user system_table/],
23 23
     cache => 0,
24 24
     cache_method => sub {
25 25
         sub {
... ...
@@ -57,26 +57,45 @@ has [qw/connector dsn password quote user/],
57 57
     stash => sub { {} },
58 58
     tag_parse => 1;
59 59
 
60
-sub query_builder {
60
+sub available_datatype {
61 61
     my $self = shift;
62
-    my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
63 62
     
64
-    # DEPRECATED
65
-    $builder->register_tag(
66
-        '?'     => \&DBIx::Custom::Tag::placeholder,
67
-        '='     => \&DBIx::Custom::Tag::equal,
68
-        '<>'    => \&DBIx::Custom::Tag::not_equal,
69
-        '>'     => \&DBIx::Custom::Tag::greater_than,
70
-        '<'     => \&DBIx::Custom::Tag::lower_than,
71
-        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
72
-        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
73
-        'like'  => \&DBIx::Custom::Tag::like,
74
-        'in'    => \&DBIx::Custom::Tag::in,
75
-        'insert_param' => \&DBIx::Custom::Tag::insert_param,
76
-        'update_param' => \&DBIx::Custom::Tag::update_param
77
-    );
78
-    $builder->register_tag($self->{_tags} || {});
79
-    return $builder;
63
+    my $data_types = '';
64
+    foreach my $i (-1000 .. 1000) {
65
+         my $type_info = $self->dbh->type_info($i);
66
+         my $data_type = $type_info->{DATA_TYPE};
67
+         my $type_name = $type_info->{TYPE_NAME};
68
+         $data_types .= "$data_type ($type_name)\n"
69
+           if defined $data_type;
70
+    }
71
+    return "Data Type maybe equal to Type Name" unless $data_types;
72
+    $data_types = "Data Type (Type name)\n" . $data_types;
73
+    return $data_types;
74
+}
75
+
76
+sub show_datatype {
77
+    my ($self, $table) = @_;
78
+    
79
+    
80
+}
81
+
82
+sub show_typename {
83
+    
84
+}
85
+
86
+sub available_typename {
87
+    my $self = shift;
88
+    
89
+    # Type Names
90
+    my $type_names = {};
91
+    $self->each_column(sub {
92
+        my ($self, $table, $column, $column_info) = @_;
93
+        $type_names->{$column_info->{TYPE_NAME}} = 1
94
+          if $column_info->{TYPE_NAME};
95
+    });
96
+    my @output = sort keys %$type_names;
97
+    unshift @output, "Type Name";
98
+    return join "\n", @output;
80 99
 }
81 100
 
82 101
 our $AUTOLOAD;
... ...
@@ -281,6 +300,8 @@ sub create_model {
281 300
 
282 301
 sub each_column {
283 302
     my ($self, $cb) = @_;
303
+
304
+    my $re = $self->system_table;
284 305
     
285 306
     # Iterate all tables
286 307
     my $sth_tables = $self->dbh->table_info;
... ...
@@ -288,6 +309,7 @@ sub each_column {
288 309
         
289 310
         # Table
290 311
         my $table = $table_info->{TABLE_NAME};
312
+        next if defined $re && $table =~ /$re/;
291 313
         
292 314
         # Iterate all columns
293 315
         my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
... ...
@@ -298,15 +320,21 @@ sub each_column {
298 320
     }
299 321
 }
300 322
 
323
+
324
+
325
+
301 326
 sub each_table {
302 327
     my ($self, $cb) = @_;
303 328
     
329
+    my $re = $self->system_table;
330
+    
304 331
     # Iterate all tables
305 332
     my $sth_tables = $self->dbh->table_info;
306 333
     while (my $table_info = $sth_tables->fetchrow_hashref) {
307 334
         
308 335
         # Table
309 336
         my $table = $table_info->{TABLE_NAME};
337
+        next if defined $re && $table =~ /$re/;
310 338
         $self->$cb($table, $table_info);
311 339
     }
312 340
 }
... ...
@@ -741,6 +769,28 @@ sub order {
741 769
     return DBIx::Custom::Order->new(dbi => $self, @_);
742 770
 }
743 771
 
772
+sub query_builder {
773
+    my $self = shift;
774
+    my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
775
+    
776
+    # DEPRECATED
777
+    $builder->register_tag(
778
+        '?'     => \&DBIx::Custom::Tag::placeholder,
779
+        '='     => \&DBIx::Custom::Tag::equal,
780
+        '<>'    => \&DBIx::Custom::Tag::not_equal,
781
+        '>'     => \&DBIx::Custom::Tag::greater_than,
782
+        '<'     => \&DBIx::Custom::Tag::lower_than,
783
+        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
784
+        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
785
+        'like'  => \&DBIx::Custom::Tag::like,
786
+        'in'    => \&DBIx::Custom::Tag::in,
787
+        'insert_param' => \&DBIx::Custom::Tag::insert_param,
788
+        'update_param' => \&DBIx::Custom::Tag::update_param
789
+    );
790
+    $builder->register_tag($self->{_tags} || {});
791
+    return $builder;
792
+}
793
+
744 794
 sub register_filter {
745 795
     my $self = shift;
746 796
     
... ...
@@ -899,37 +949,6 @@ sub setup_model {
899 949
     return $self;
900 950
 }
901 951
 
902
-sub available_datatype {
903
-    my $self = shift;
904
-    
905
-    my $data_types = '';
906
-    foreach my $i (-1000 .. 1000) {
907
-         my $type_info = $self->dbh->type_info($i);
908
-         my $data_type = $type_info->{DATA_TYPE};
909
-         my $type_name = $type_info->{TYPE_NAME};
910
-         $data_types .= "$data_type ($type_name)\n"
911
-           if defined $data_type;
912
-    }
913
-    return "Data Type maybe equal to Type Name" unless $data_types;
914
-    $data_types = "Data Type (Type name)\n" . $data_types;
915
-    return $data_types;
916
-}
917
-
918
-sub available_typename {
919
-    my $self = shift;
920
-    
921
-    # Type Names
922
-    my $type_names = {};
923
-    $self->each_column(sub {
924
-        my ($self, $table, $column, $column_info) = @_;
925
-        $type_names->{$column_info->{TYPE_NAME}} = 1
926
-          if $column_info->{TYPE_NAME};
927
-    });
928
-    my @output = sort keys %$type_names;
929
-    unshift @output, "Type Name";
930
-    return join "\n", @output;
931
-}
932
-
933 952
 sub type_rule {
934 953
     my $self = shift;
935 954
     
... ...
@@ -1995,6 +2014,18 @@ Note that you don't have to specify like '[\w]'.
1995 2014
 Separator whichi join table and column.
1996 2015
 This is used by C<column> and C<mycolumn> method.
1997 2016
 
2017
+=head2 C<system_table EXPERIMENTAL>
2018
+
2019
+    my $system_table = $self->system_table;
2020
+    $dbi = $self->system_table(qr/pg_/);
2021
+
2022
+Regex matching system table.
2023
+this regex match is used by C<each_table> method and C<each_column> method
2024
+System table is ignored.
2025
+C<type_rule> method and C<setup_model> method call
2026
+C<each_table>, so if you set C<system_table> properly,
2027
+The performance is up.
2028
+
1998 2029
 =head2 C<tag_parse>
1999 2030
 
2000 2031
     my $tag_parse = $dbi->tag_parse(0);
+31
t/common-postgresql.t
... ...
@@ -30,6 +30,37 @@ use DBIx::Custom;
30 30
     has dsn => "dbi:Pg:dbname=dbix_custom";
31 31
     has user  => 'dbix_custom';
32 32
     has password => 'dbix_custom';
33
+    has system_table => sub {
34
+
35
+        return qr/^(
36
+            pg_|column_|role_|view_|sql_
37
+            |applicable_roles
38
+            |check_constraints
39
+            |columns
40
+            |constraint_column_usage
41
+            |constraint_table_usage
42
+            |data_type_privileges
43
+            |domain_constraints
44
+            |domain_udt_usage
45
+            |domains
46
+            |element_types
47
+            |enabled_roles
48
+            |information_schema_catalog_name
49
+            |key_column_usage
50
+            |parameters
51
+            |referential_constraints
52
+            |routine_privileges
53
+            |routines
54
+            |schemata
55
+            |table_constraints
56
+            |table_privileges
57
+            |tables
58
+            |triggered_update_columns
59
+            |triggers
60
+            |usage_privileges
61
+            |views
62
+        )/x
63
+    };
33 64
     
34 65
     sub create_table1 { 'create table table1 (key1 varchar(255), key2 varchar(255));' }
35 66
     sub create_table1_2 {'create table table1 (key1 varchar(255), key2 varchar(255), '