... | ... |
@@ -1,3 +1,5 @@ |
1 |
+0.1732 |
|
2 |
+ - removed EXPERIMETNAL flag from like_value |
|
1 | 3 |
0.1731 |
2 | 4 |
- removed DEPRECATED status from insert method's id option |
3 | 5 |
- renamed EXPERIMENTAL insert_or_update to update_or_insert |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
use Object::Simple -base; |
3 | 3 |
|
4 |
-our $VERSION = '0.1731'; |
|
4 |
+our $VERSION = '0.1732'; |
|
5 | 5 |
use 5.008001; |
6 | 6 |
|
7 | 7 |
use Carp 'croak'; |
... | ... |
@@ -2151,14 +2151,6 @@ Note that L<DBIx::Connector> must be installed. |
2151 | 2151 |
|
2152 | 2152 |
Data source name, used when C<connect> method is executed. |
2153 | 2153 |
|
2154 |
-=head2 C<option> |
|
2155 |
- |
|
2156 |
- my $option = $dbi->option; |
|
2157 |
- $dbi = $dbi->option($option); |
|
2158 |
- |
|
2159 |
-L<DBI> option, used when C<connect> method is executed. |
|
2160 |
-Each value in option override the value of C<default_option>. |
|
2161 |
- |
|
2162 | 2154 |
=head2 C<default_option> |
2163 | 2155 |
|
2164 | 2156 |
my $default_option = $dbi->default_option; |
... | ... |
@@ -2173,6 +2165,15 @@ default to the following values. |
2173 | 2165 |
AutoCommit => 1, |
2174 | 2166 |
} |
2175 | 2167 |
|
2168 |
+=head2 C<exclude_table> |
|
2169 |
+ |
|
2170 |
+ my $exclude_table = $dbi->exclude_table; |
|
2171 |
+ $dbi = $dbi->exclude_table(qr/pg_/); |
|
2172 |
+ |
|
2173 |
+Excluded table regex. |
|
2174 |
+C<each_column>, C<each_table>, C<type_rule>, |
|
2175 |
+and C<setup_model> methods ignore matching tables. |
|
2176 |
+ |
|
2176 | 2177 |
=head2 C<filters> |
2177 | 2178 |
|
2178 | 2179 |
my $filters = $dbi->filters; |
... | ... |
@@ -2194,6 +2195,14 @@ Get last successed SQL executed by C<execute> method. |
2194 | 2195 |
|
2195 | 2196 |
Models, included by C<include_model> method. |
2196 | 2197 |
|
2198 |
+=head2 C<option> |
|
2199 |
+ |
|
2200 |
+ my $option = $dbi->option; |
|
2201 |
+ $dbi = $dbi->option($option); |
|
2202 |
+ |
|
2203 |
+L<DBI> option, used when C<connect> method is executed. |
|
2204 |
+Each value in option override the value of C<default_option>. |
|
2205 |
+ |
|
2197 | 2206 |
=head2 C<password> |
2198 | 2207 |
|
2199 | 2208 |
my $password = $dbi->password; |
... | ... |
@@ -2246,15 +2255,6 @@ and C<select> method's column option. |
2246 | 2255 |
|
2247 | 2256 |
Default to C<.>. |
2248 | 2257 |
|
2249 |
-=head2 C<exclude_table> |
|
2250 |
- |
|
2251 |
- my $exclude_table = $dbi->exclude_table; |
|
2252 |
- $dbi = $dbi->exclude_table(qr/pg_/); |
|
2253 |
- |
|
2254 |
-Excluded table regex. |
|
2255 |
-C<each_column>, C<each_table>, C<type_rule>, |
|
2256 |
-and C<setup_model> methods ignore matching tables. |
|
2257 |
- |
|
2258 | 2258 |
=head2 C<tag_parse> |
2259 | 2259 |
|
2260 | 2260 |
my $tag_parse = $dbi->tag_parse(0); |
... | ... |
@@ -2780,6 +2780,26 @@ get table infomation except for one which match C<exclude> pattern. |
2780 | 2780 |
|
2781 | 2781 |
You can set this value to C<user_table_info>. |
2782 | 2782 |
|
2783 |
+=head2 C<helper> |
|
2784 |
+ |
|
2785 |
+ $dbi->helper( |
|
2786 |
+ update_or_insert => sub { |
|
2787 |
+ my $self = shift; |
|
2788 |
+ |
|
2789 |
+ # Process |
|
2790 |
+ }, |
|
2791 |
+ find_or_create => sub { |
|
2792 |
+ my $self = shift; |
|
2793 |
+ |
|
2794 |
+ # Process |
|
2795 |
+ } |
|
2796 |
+ ); |
|
2797 |
+ |
|
2798 |
+Register helper. These helper is called directly from L<DBIx::Custom> object. |
|
2799 |
+ |
|
2800 |
+ $dbi->update_or_insert; |
|
2801 |
+ $dbi->find_or_create; |
|
2802 |
+ |
|
2783 | 2803 |
=head2 C<insert> |
2784 | 2804 |
|
2785 | 2805 |
$dbi->insert({title => 'Perl', author => 'Ken'}, table => 'book'); |
... | ... |
@@ -2949,13 +2969,19 @@ See L<DBIx::Custom::Model> to know model features. |
2949 | 2969 |
|
2950 | 2970 |
=head2 C<insert_timestamp> |
2951 | 2971 |
|
2952 |
- $dbi->insert_timestamp( |
|
2953 |
- [qw/created_at updated_at/] => sub { localtime }); |
|
2972 |
+$dbi->insert_timestamp( |
|
2973 |
+ [qw/created_at updated_at/] |
|
2974 |
+ => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") } |
|
2975 |
+); |
|
2954 | 2976 |
|
2955 |
-Parameter for timestamp columns when C<insert> method is executed |
|
2977 |
+Timestamp value when C<insert> method is executed |
|
2956 | 2978 |
with C<timestamp> option. |
2957 | 2979 |
|
2958 |
-If multiple column are specified, same value is used. |
|
2980 |
+If C<insert_timestamp> is set and C<insert> method is executed |
|
2981 |
+with C<timestamp> option, column C<created_at> and C<update_at> |
|
2982 |
+is automatically set to the value like "2010-10-11 10:12:54". |
|
2983 |
+ |
|
2984 |
+$dbi->insert($param, table => 'book', timestamp => 1); |
|
2959 | 2985 |
|
2960 | 2986 |
=head2 C<like_value EXPERIMENTAL> |
2961 | 2987 |
|
... | ... |
@@ -2979,26 +3005,6 @@ Merge parameters. |
2979 | 3005 |
|
2980 | 3006 |
{key1 => [1, 1], key2 => 2} |
2981 | 3007 |
|
2982 |
-=head2 C<helper> |
|
2983 |
- |
|
2984 |
- $dbi->helper( |
|
2985 |
- update_or_insert => sub { |
|
2986 |
- my $self = shift; |
|
2987 |
- |
|
2988 |
- # Process |
|
2989 |
- }, |
|
2990 |
- find_or_create => sub { |
|
2991 |
- my $self = shift; |
|
2992 |
- |
|
2993 |
- # Process |
|
2994 |
- } |
|
2995 |
- ); |
|
2996 |
- |
|
2997 |
-Register helper. These helper is called directly from L<DBIx::Custom> object. |
|
2998 |
- |
|
2999 |
- $dbi->update_or_insert; |
|
3000 |
- $dbi->find_or_create; |
|
3001 |
- |
|
3002 | 3008 |
=head2 C<model> |
3003 | 3009 |
|
3004 | 3010 |
my $model = $dbi->model('book'); |
... | ... |
@@ -3055,80 +3061,6 @@ Create a new L<DBIx::Custom::Order> object. |
3055 | 3061 |
|
3056 | 3062 |
Register filters, used by C<filter> option of many methods. |
3057 | 3063 |
|
3058 |
-=head2 C<type_rule> |
|
3059 |
- |
|
3060 |
- $dbi->type_rule( |
|
3061 |
- into1 => { |
|
3062 |
- date => sub { ... }, |
|
3063 |
- datetime => sub { ... } |
|
3064 |
- }, |
|
3065 |
- into2 => { |
|
3066 |
- date => sub { ... }, |
|
3067 |
- datetime => sub { ... } |
|
3068 |
- }, |
|
3069 |
- from1 => { |
|
3070 |
- # DATE |
|
3071 |
- 9 => sub { ... }, |
|
3072 |
- # DATETIME or TIMESTAMP |
|
3073 |
- 11 => sub { ... }, |
|
3074 |
- } |
|
3075 |
- from2 => { |
|
3076 |
- # DATE |
|
3077 |
- 9 => sub { ... }, |
|
3078 |
- # DATETIME or TIMESTAMP |
|
3079 |
- 11 => sub { ... }, |
|
3080 |
- } |
|
3081 |
- ); |
|
3082 |
- |
|
3083 |
-Filtering rule when data is send into and get from database. |
|
3084 |
-This has a little complex problem. |
|
3085 |
- |
|
3086 |
-In C<into1> and C<into2> you can specify |
|
3087 |
-type name as same as type name defined |
|
3088 |
-by create table, such as C<DATETIME> or C<DATE>. |
|
3089 |
- |
|
3090 |
-Note that type name and data type don't contain upper case. |
|
3091 |
-If these contain upper case charactor, you convert it to lower case. |
|
3092 |
- |
|
3093 |
-C<into2> is executed after C<into1>. |
|
3094 |
- |
|
3095 |
-Type rule of C<into1> and C<into2> is enabled on the following |
|
3096 |
-column name. |
|
3097 |
- |
|
3098 |
-=over 4 |
|
3099 |
- |
|
3100 |
-=item 1. column name |
|
3101 |
- |
|
3102 |
- issue_date |
|
3103 |
- issue_datetime |
|
3104 |
- |
|
3105 |
-This need C<table> option in each method. |
|
3106 |
- |
|
3107 |
-=item 2. table name and column name, separator is dot |
|
3108 |
- |
|
3109 |
- book.issue_date |
|
3110 |
- book.issue_datetime |
|
3111 |
- |
|
3112 |
-=back |
|
3113 |
- |
|
3114 |
-You get all type name used in database by C<available_typename>. |
|
3115 |
- |
|
3116 |
- print $dbi->available_typename; |
|
3117 |
- |
|
3118 |
-In C<from1> and C<from2> you specify data type, not type name. |
|
3119 |
-C<from2> is executed after C<from1>. |
|
3120 |
-You get all data type by C<available_datatype>. |
|
3121 |
- |
|
3122 |
- print $dbi->available_datatype; |
|
3123 |
- |
|
3124 |
-You can also specify multiple types at once. |
|
3125 |
- |
|
3126 |
- $dbi->type_rule( |
|
3127 |
- into1 => [ |
|
3128 |
- [qw/DATE DATETIME/] => sub { ... }, |
|
3129 |
- ], |
|
3130 |
- ); |
|
3131 |
- |
|
3132 | 3064 |
=head2 C<select> |
3133 | 3065 |
|
3134 | 3066 |
my $result = $dbi->select( |
... | ... |
@@ -3344,6 +3276,87 @@ Where clause. |
3344 | 3276 |
|
3345 | 3277 |
=back |
3346 | 3278 |
|
3279 |
+=head2 C<setup_model> |
|
3280 |
+ |
|
3281 |
+ $dbi->setup_model; |
|
3282 |
+ |
|
3283 |
+Setup all model objects. |
|
3284 |
+C<columns> of model object is automatically set, parsing database information. |
|
3285 |
+ |
|
3286 |
+=head2 C<type_rule> |
|
3287 |
+ |
|
3288 |
+ $dbi->type_rule( |
|
3289 |
+ into1 => { |
|
3290 |
+ date => sub { ... }, |
|
3291 |
+ datetime => sub { ... } |
|
3292 |
+ }, |
|
3293 |
+ into2 => { |
|
3294 |
+ date => sub { ... }, |
|
3295 |
+ datetime => sub { ... } |
|
3296 |
+ }, |
|
3297 |
+ from1 => { |
|
3298 |
+ # DATE |
|
3299 |
+ 9 => sub { ... }, |
|
3300 |
+ # DATETIME or TIMESTAMP |
|
3301 |
+ 11 => sub { ... }, |
|
3302 |
+ } |
|
3303 |
+ from2 => { |
|
3304 |
+ # DATE |
|
3305 |
+ 9 => sub { ... }, |
|
3306 |
+ # DATETIME or TIMESTAMP |
|
3307 |
+ 11 => sub { ... }, |
|
3308 |
+ } |
|
3309 |
+ ); |
|
3310 |
+ |
|
3311 |
+Filtering rule when data is send into and get from database. |
|
3312 |
+This has a little complex problem. |
|
3313 |
+ |
|
3314 |
+In C<into1> and C<into2> you can specify |
|
3315 |
+type name as same as type name defined |
|
3316 |
+by create table, such as C<DATETIME> or C<DATE>. |
|
3317 |
+ |
|
3318 |
+Note that type name and data type don't contain upper case. |
|
3319 |
+If these contain upper case charactor, you convert it to lower case. |
|
3320 |
+ |
|
3321 |
+C<into2> is executed after C<into1>. |
|
3322 |
+ |
|
3323 |
+Type rule of C<into1> and C<into2> is enabled on the following |
|
3324 |
+column name. |
|
3325 |
+ |
|
3326 |
+=over 4 |
|
3327 |
+ |
|
3328 |
+=item 1. column name |
|
3329 |
+ |
|
3330 |
+ issue_date |
|
3331 |
+ issue_datetime |
|
3332 |
+ |
|
3333 |
+This need C<table> option in each method. |
|
3334 |
+ |
|
3335 |
+=item 2. table name and column name, separator is dot |
|
3336 |
+ |
|
3337 |
+ book.issue_date |
|
3338 |
+ book.issue_datetime |
|
3339 |
+ |
|
3340 |
+=back |
|
3341 |
+ |
|
3342 |
+You get all type name used in database by C<available_typename>. |
|
3343 |
+ |
|
3344 |
+ print $dbi->available_typename; |
|
3345 |
+ |
|
3346 |
+In C<from1> and C<from2> you specify data type, not type name. |
|
3347 |
+C<from2> is executed after C<from1>. |
|
3348 |
+You get all data type by C<available_datatype>. |
|
3349 |
+ |
|
3350 |
+ print $dbi->available_datatype; |
|
3351 |
+ |
|
3352 |
+You can also specify multiple types at once. |
|
3353 |
+ |
|
3354 |
+ $dbi->type_rule( |
|
3355 |
+ into1 => [ |
|
3356 |
+ [qw/DATE DATETIME/] => sub { ... }, |
|
3357 |
+ ], |
|
3358 |
+ ); |
|
3359 |
+ |
|
3347 | 3360 |
=head2 C<update> |
3348 | 3361 |
|
3349 | 3362 |
$dbi->update({title => 'Perl'}, table => 'book', where => {id => 4}); |
... | ... |
@@ -3468,6 +3481,7 @@ is executed, the following SQL is executed. |
3468 | 3481 |
|
3469 | 3482 |
=back |
3470 | 3483 |
|
3484 |
+ |
|
3471 | 3485 |
=head2 C<update_all> |
3472 | 3486 |
|
3473 | 3487 |
$dbi->update_all({title => 'Perl'}, table => 'book', ); |
... | ... |
@@ -3517,26 +3531,21 @@ select method is used to check the row is already exists. |
3517 | 3531 |
|
3518 | 3532 |
=head2 C<update_timestamp> |
3519 | 3533 |
|
3520 |
- $dbi->update_timestamp(updated_at => sub { localtime }); |
|
3521 |
- |
|
3522 |
-Parameter for timestamp columns when C<update> method is executed |
|
3523 |
-with C<timestamp> option. |
|
3524 |
- |
|
3525 |
-=head2 C<where> |
|
3526 |
- |
|
3527 |
- my $where = $dbi->where( |
|
3528 |
- clause => ['and', 'title = :title', 'author = :author'], |
|
3529 |
- param => {title => 'Perl', author => 'Ken'} |
|
3534 |
+ $dbi->update_timestamp( |
|
3535 |
+ updated_at |
|
3536 |
+ => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") } |
|
3530 | 3537 |
); |
3531 | 3538 |
|
3532 |
-Create a new L<DBIx::Custom::Where> object. |
|
3533 |
- |
|
3534 |
-=head2 C<setup_model> |
|
3539 |
+Timestamp value when C<update> method is executed |
|
3540 |
+with C<timestamp> option. |
|
3535 | 3541 |
|
3536 |
- $dbi->setup_model; |
|
3542 |
+If C<insert_timestamp> is set and C<insert> method is executed |
|
3543 |
+with C<timestamp> option, column C<update_at> |
|
3544 |
+is automatically set to the value like "2010-10-11 10:12:54". |
|
3537 | 3545 |
|
3538 |
-Setup all model objects. |
|
3539 |
-C<columns> of model object is automatically set, parsing database information. |
|
3546 |
+>|perl| |
|
3547 |
+$dbi->update($param, table => 'book', timestamp => 1); |
|
3548 |
+||< |
|
3540 | 3549 |
|
3541 | 3550 |
=head2 C<show_datatype> |
3542 | 3551 |
|
... | ... |
@@ -3568,6 +3577,27 @@ Show type name of the columns of specified table. |
3568 | 3577 |
|
3569 | 3578 |
This type name is used in C<type_rule>'s C<into1> and C<into2>. |
3570 | 3579 |
|
3580 |
+=head2 C<values_clause> |
|
3581 |
+ |
|
3582 |
+ my $values_clause = $dbi->values_clause({title => 'a', age => 2}); |
|
3583 |
+ |
|
3584 |
+Create values clause. |
|
3585 |
+ |
|
3586 |
+ (title, author) values (title = :title, age = :age); |
|
3587 |
+ |
|
3588 |
+You can use this in insert statement. |
|
3589 |
+ |
|
3590 |
+ my $insert_sql = "insert into book $values_clause"; |
|
3591 |
+ |
|
3592 |
+=head2 C<where> |
|
3593 |
+ |
|
3594 |
+ my $where = $dbi->where( |
|
3595 |
+ clause => ['and', 'title = :title', 'author = :author'], |
|
3596 |
+ param => {title => 'Perl', author => 'Ken'} |
|
3597 |
+ ); |
|
3598 |
+ |
|
3599 |
+Create a new L<DBIx::Custom::Where> object. |
|
3600 |
+ |
|
3571 | 3601 |
=head1 ENVIRONMENTAL VARIABLES |
3572 | 3602 |
|
3573 | 3603 |
=head2 C<DBIX_CUSTOM_DEBUG> |