Showing 4 changed files with 114 additions and 3 deletions
+3
Changes
... ...
@@ -1,3 +1,6 @@
1
+0.1622
2
+  deprecated DBIx::Custom::SQLite and DBIx::Custom::MySQL
3
+  
1 4
 0.1621
2 5
   cleanup (removed undocumented features)
3 6
 0.1620
+19 -3
lib/DBIx/Custom.pm
... ...
@@ -1,6 +1,6 @@
1 1
 package DBIx::Custom;
2 2
 
3
-our $VERSION = '0.1621';
3
+our $VERSION = '0.1622';
4 4
 
5 5
 use 5.008001;
6 6
 use strict;
... ...
@@ -16,7 +16,7 @@ use DBIx::Custom::QueryBuilder;
16 16
 use Encode qw/encode_utf8 decode_utf8/;
17 17
 
18 18
 __PACKAGE__->attr([qw/data_source dbh default_bind_filter
19
-                      default_fetch_filter password user/]);
19
+                      dbi_options default_fetch_filter password user/]);
20 20
 
21 21
 __PACKAGE__->attr(cache => 1);
22 22
 __PACKAGE__->attr(cache_method => sub {
... ...
@@ -84,6 +84,19 @@ sub helper {
84 84
     return $self;
85 85
 }
86 86
 
87
+#sub new {
88
+#    my $self = shift->SUPER::new(@_);
89
+#    
90
+#    # Check attribute names
91
+#    my @attrs = keys %$self;
92
+#    foreach my $attr (@attrs) {
93
+#        croak qq{"$attr" is invalid attribute name"}
94
+#          unless $self->can($attr);
95
+#    }
96
+#    
97
+#    return $self;
98
+#}
99
+
87 100
 sub connect {
88 101
     my $proto = shift;
89 102
     
... ...
@@ -92,10 +105,13 @@ sub connect {
92 105
     
93 106
     # Information
94 107
     my $data_source = $self->data_source;
108
+    
109
+    croak qq{"data_source" must be specfied to connect method"}
110
+      unless $data_source;
111
+    
95 112
     my $user        = $self->user;
96 113
     my $password    = $self->password;
97 114
     
98
-    
99 115
     # Connect
100 116
     my $dbh = eval {DBI->connect(
101 117
         $data_source,
+46
lib/DBIx/Custom/Guides.pod
... ...
@@ -383,6 +383,52 @@ Note that in fetch filter, column names must be lower case
383 383
 even if the column name conatains upper case charactors.
384 384
 This is requirment not to depend database systems.
385 385
 
386
+B<Filter examples>
387
+
388
+MySQL
389
+
390
+    # Time::Piece object to DATETIME format
391
+    tp_to_datetime => sub {
392
+        return shift->strftime('%Y-%m-%d %H:%M:%S');
393
+    }
394
+    
395
+    # Time::Piece object to DATE format
396
+    tp_to_date => sub {
397
+        return shift->strftime('%Y-%m-%d');
398
+    },
399
+    
400
+    # DATETIME to Time::Piece object
401
+    datetime_to_tp => sub {
402
+        return Time::Piece->strptime(shift, '%Y-%m-%d %H:%M:%S');
403
+    }
404
+    
405
+    # DATE to Time::Piece object
406
+    date_to_tp => sub {
407
+        return Time::Piece->strptime(shift, '%Y-%m-%d');
408
+    }
409
+
410
+SQLite
411
+    
412
+    # Time::Piece object to DATETIME format
413
+    tp_to_datetime => sub {
414
+        return shift->strftime('%Y-%m-%d %H:%M:%S');
415
+    }
416
+    
417
+    # Time::Piece object to DATE format
418
+    tp_to_date => sub {
419
+        return shift->strftime('%Y-%m-%d');
420
+    },
421
+    
422
+    # DATETIME to Time::Piece object
423
+    datetime_to_tp => sub {
424
+        return Time::Piece->strptime(shift, $FORMATS->{db_datetime});
425
+    }
426
+    
427
+    # DATE to Time::Piece object
428
+    date_to_tp => sub {
429
+        return Time::Piece->strptime(shift, $FORMATS->{db_date});
430
+    }
431
+    
386 432
 =head2 6. Get high performance
387 433
 
388 434
 =head3 Disable filter checking
+46
lib/DBIx/Custom/Guides/Ja.pod
... ...
@@ -458,6 +458,52 @@ C<title>の値にはデフォルトのフィルタであるC<encode_utf8>が適
458 458
 C<author>の値にはC<to_upper_case>が適用されます。
459 459
 C<price>にはundefを設定しているのでフィルタが解除されます。
460 460
 
461
+B<フィルタのサンプル>
462
+
463
+MySQL
464
+
465
+    # Time::Piece object to DATETIME format
466
+    tp_to_datetime => sub {
467
+        return shift->strftime('%Y-%m-%d %H:%M:%S');
468
+    }
469
+    
470
+    # Time::Piece object to DATE format
471
+    tp_to_date => sub {
472
+        return shift->strftime('%Y-%m-%d');
473
+    }
474
+    
475
+    # DATETIME to Time::Piece object
476
+    datetime_to_tp => sub {
477
+        return Time::Piece->strptime(shift, '%Y-%m-%d %H:%M:%S');
478
+    }
479
+    
480
+    # DATE to Time::Piece object
481
+    date_to_tp => sub {
482
+        return Time::Piece->strptime(shift, '%Y-%m-%d');
483
+    }
484
+
485
+SQLite
486
+    
487
+    # Time::Piece object to DATETIME format
488
+    tp_to_datetime => sub {
489
+        return shift->strftime('%Y-%m-%d %H:%M:%S');
490
+    }
491
+    
492
+    # Time::Piece object to DATE format
493
+    tp_to_date => sub {
494
+        return shift->strftime('%Y-%m-%d');
495
+    }
496
+    
497
+    # DATETIME to Time::Piece object
498
+    datetime_to_tp => sub {
499
+        return Time::Piece->strptime(shift, $FORMATS->{db_datetime});
500
+    }
501
+    
502
+    # DATE to Time::Piece object
503
+    date_to_tp => sub {
504
+        return Time::Piece->strptime(shift, $FORMATS->{db_date});
505
+    }
506
+
461 507
 =head3 行のフェッチ時のフィルタリング
462 508
 
463 509
 行をフェッチするときのフィルタも設定することができます。