sqlfilter option is renamed to after_build_sql, sqlfilt...
...er is DEPRECATED!
| ... | ... |
@@ -1,3 +1,10 @@ |
| 1 |
+0.1724 |
|
| 2 |
+ - sqlfilter option is renamed to after_build_sql, sqlfilter is DEPRECATED! |
|
| 3 |
+ - removed EXPERIMENTAL flag from DBIx::Custom::Mapper |
|
| 4 |
+ - removed EXPERIMENTAL flag from the following DBIx::Custom methods |
|
| 5 |
+ insert_timestamp, mapper, update_timestamp |
|
| 6 |
+ - removed EXPERIMENTAL flag from the following DBIx::Custom method's option |
|
| 7 |
+ timestamp, |
|
| 1 | 8 |
0.1723 |
| 2 | 9 |
- removed EXPERIMENTAL call_dbi method from DBIx::Custom::Model |
| 3 | 10 |
- removed EXPERIMENTAL map_param method from DBIx::Custom |
| ... | ... |
@@ -1,7 +1,7 @@ |
| 1 | 1 |
package DBIx::Custom; |
| 2 | 2 |
use Object::Simple -base; |
| 3 | 3 |
|
| 4 |
-our $VERSION = '0.1723'; |
|
| 4 |
+our $VERSION = '0.1724'; |
|
| 5 | 5 |
use 5.008001; |
| 6 | 6 |
|
| 7 | 7 |
use Carp 'croak'; |
| ... | ... |
@@ -372,7 +372,7 @@ sub each_table {
|
| 372 | 372 |
} |
| 373 | 373 |
} |
| 374 | 374 |
|
| 375 |
-our %VALID_ARGS = map { $_ => 1 } qw/append allow_delete_all
|
|
| 375 |
+our %VALID_ARGS = map { $_ => 1 } qw/append after_build_sql allow_delete_all
|
|
| 376 | 376 |
allow_update_all bind_type column filter id join param prefix primary_key |
| 377 | 377 |
query relation sqlfilter table table_alias timestamp type type_rule_off |
| 378 | 378 |
type_rule1_off type_rule2_off wrap/; |
| ... | ... |
@@ -400,7 +400,8 @@ sub execute {
|
| 400 | 400 |
}; |
| 401 | 401 |
my $query_return = delete $args{query};
|
| 402 | 402 |
my $table_alias = delete $args{table_alias} || {};
|
| 403 |
- my $sqlfilter = $args{sqlfilter};
|
|
| 403 |
+ my $after_build_sql = $args{after_build_sql} || $args{sqlfilter};
|
|
| 404 |
+ warn "sqlfilter option is DEPRECATED" if $args{sqlfilter};
|
|
| 404 | 405 |
my $id = delete $args{id};
|
| 405 | 406 |
my $primary_key = delete $args{primary_key};
|
| 406 | 407 |
croak "insert method primary_key option " . |
| ... | ... |
@@ -419,7 +420,7 @@ sub execute {
|
| 419 | 420 |
unless $VALID_ARGS{$name};
|
| 420 | 421 |
} |
| 421 | 422 |
|
| 422 |
- $query = $self->_create_query($query, $sqlfilter) unless ref $query; |
|
| 423 |
+ $query = $self->_create_query($query, $after_build_sql) unless ref $query; |
|
| 423 | 424 |
|
| 424 | 425 |
# Save query |
| 425 | 426 |
$self->last_sql($query->sql); |
| ... | ... |
@@ -1206,7 +1207,7 @@ sub where { DBIx::Custom::Where->new(dbi => shift, @_) }
|
| 1206 | 1207 |
|
| 1207 | 1208 |
sub _create_query {
|
| 1208 | 1209 |
|
| 1209 |
- my ($self, $source, $sqlfilter) = @_; |
|
| 1210 |
+ my ($self, $source, $after_build_sql) = @_; |
|
| 1210 | 1211 |
|
| 1211 | 1212 |
# Cache |
| 1212 | 1213 |
my $cache = $self->cache; |
| ... | ... |
@@ -1252,9 +1253,9 @@ sub _create_query {
|
| 1252 | 1253 |
} |
| 1253 | 1254 |
|
| 1254 | 1255 |
# Filter SQL |
| 1255 |
- if ($sqlfilter) {
|
|
| 1256 |
+ if ($after_build_sql) {
|
|
| 1256 | 1257 |
my $sql = $query->sql; |
| 1257 |
- $sql = $sqlfilter->($sql); |
|
| 1258 |
+ $sql = $after_build_sql->($sql); |
|
| 1258 | 1259 |
$query->sql($sql); |
| 1259 | 1260 |
} |
| 1260 | 1261 |
|
| ... | ... |
@@ -2379,9 +2380,9 @@ prefix before table name section. |
| 2379 | 2380 |
|
| 2380 | 2381 |
Same as C<execute> method's C<query> option. |
| 2381 | 2382 |
|
| 2382 |
-=item C<sqlfilter> |
|
| 2383 |
+=item C<after_build_sql> |
|
| 2383 | 2384 |
|
| 2384 |
-Same as C<execute> method's C<sqlfilter> option. |
|
| 2385 |
+Same as C<execute> method's C<after_build_sql> option. |
|
| 2385 | 2386 |
|
| 2386 | 2387 |
=item C<table> |
| 2387 | 2388 |
|
| ... | ... |
@@ -2602,28 +2603,25 @@ and don't forget to sort $row values by $row key asc order. |
| 2602 | 2603 |
|
| 2603 | 2604 |
See C<id> option. |
| 2604 | 2605 |
|
| 2605 |
-=item C<sqlfilter> |
|
| 2606 |
+=item C<after_build_sql> |
|
| 2606 | 2607 |
|
| 2607 |
-SQL filter function. |
|
| 2608 |
+You can filter sql after the sql is build. |
|
| 2608 | 2609 |
|
| 2609 |
- sqlfilter => $code_ref |
|
| 2610 |
+ after_build_sql => $code_ref |
|
| 2610 | 2611 |
|
| 2611 |
-This option is generally for Oracle and SQL Server paging process. |
|
| 2612 |
- |
|
| 2613 |
- my $limit = sub {
|
|
| 2614 |
- my ($sql, $count, $offset) = @_; |
|
| 2615 |
- |
|
| 2616 |
- my $min = $offset + 1; |
|
| 2617 |
- my $max = $offset + $count; |
|
| 2618 |
- |
|
| 2619 |
- $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max"; |
|
| 2620 |
- |
|
| 2621 |
- return $sql; |
|
| 2622 |
- } |
|
| 2623 |
- $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
|
|
| 2624 |
- my $sql = shift; |
|
| 2625 |
- return $limit->($sql, 100, 50); |
|
| 2626 |
- }) |
|
| 2612 |
+The following one is one example. |
|
| 2613 |
+ |
|
| 2614 |
+ $dbi->select( |
|
| 2615 |
+ table => 'book', |
|
| 2616 |
+ column => 'distinct(name)', |
|
| 2617 |
+ after_build_sql => sub {
|
|
| 2618 |
+ "select count(*) from ($_[0]) as t1" |
|
| 2619 |
+ } |
|
| 2620 |
+ ); |
|
| 2621 |
+ |
|
| 2622 |
+The following SQL is executed. |
|
| 2623 |
+ |
|
| 2624 |
+ select count(*) from (select distinct(name) from book) as t1; |
|
| 2627 | 2625 |
|
| 2628 | 2626 |
=item C<table> |
| 2629 | 2627 |
|
| ... | ... |
@@ -2762,9 +2760,9 @@ Primary key. This is used by C<id> option. |
| 2762 | 2760 |
|
| 2763 | 2761 |
Same as C<execute> method's C<query> option. |
| 2764 | 2762 |
|
| 2765 |
-=item C<sqlfilter> |
|
| 2763 |
+=item C<after_build_sql> |
|
| 2766 | 2764 |
|
| 2767 |
-Same as C<execute> method's C<sqlfilter> option. |
|
| 2765 |
+Same as C<execute> method's C<after_build_sql> option. |
|
| 2768 | 2766 |
|
| 2769 | 2767 |
=item C<table> |
| 2770 | 2768 |
|
| ... | ... |
@@ -2776,7 +2774,7 @@ Table name. |
| 2776 | 2774 |
|
| 2777 | 2775 |
Same as C<execute> method's C<type_rule_off> option. |
| 2778 | 2776 |
|
| 2779 |
-=item C<timestamp EXPERIMENTAL> |
|
| 2777 |
+=item C<timestamp> |
|
| 2780 | 2778 |
|
| 2781 | 2779 |
timestamp => 1 |
| 2782 | 2780 |
|
| ... | ... |
@@ -2868,7 +2866,7 @@ You can get model object by C<model>. |
| 2868 | 2866 |
|
| 2869 | 2867 |
See L<DBIx::Custom::Model> to know model features. |
| 2870 | 2868 |
|
| 2871 |
-=head2 C<insert_timestamp EXPERIMENTAL> |
|
| 2869 |
+=head2 C<insert_timestamp> |
|
| 2872 | 2870 |
|
| 2873 | 2871 |
$dbi->insert_timestamp( |
| 2874 | 2872 |
[qw/created_at updated_at/] => sub { localtime });
|
| ... | ... |
@@ -2876,7 +2874,9 @@ See L<DBIx::Custom::Model> to know model features. |
| 2876 | 2874 |
Parameter for timestamp columns when C<insert> method is executed |
| 2877 | 2875 |
with C<timestamp> option. |
| 2878 | 2876 |
|
| 2879 |
-=head2 C<mapper EXPERIMENTAL> |
|
| 2877 |
+If multiple column are specified, same value is used. |
|
| 2878 |
+ |
|
| 2879 |
+=head2 C<mapper> |
|
| 2880 | 2880 |
|
| 2881 | 2881 |
my $mapper = $dbi->mapper(param => $param); |
| 2882 | 2882 |
|
| ... | ... |
@@ -3199,9 +3199,9 @@ Primary key. This is used by C<id> option. |
| 3199 | 3199 |
|
| 3200 | 3200 |
Same as C<execute> method's C<query> option. |
| 3201 | 3201 |
|
| 3202 |
-=item C<sqlfilter> |
|
| 3202 |
+=item C<after_build_sql> |
|
| 3203 | 3203 |
|
| 3204 |
-Same as C<execute> method's C<sqlfilter> option |
|
| 3204 |
+Same as C<execute> method's C<after_build_sql> option |
|
| 3205 | 3205 |
|
| 3206 | 3206 |
=item C<table> |
| 3207 | 3207 |
|
| ... | ... |
@@ -3324,9 +3324,9 @@ Primary key. This is used by C<id> option. |
| 3324 | 3324 |
|
| 3325 | 3325 |
Same as C<execute> method's C<query> option. |
| 3326 | 3326 |
|
| 3327 |
-=item C<sqlfilter> |
|
| 3327 |
+=item C<after_build_sql> |
|
| 3328 | 3328 |
|
| 3329 |
-Same as C<execute> method's C<sqlfilter> option. |
|
| 3329 |
+Same as C<execute> method's C<after_build_sql> option. |
|
| 3330 | 3330 |
|
| 3331 | 3331 |
=item C<table> |
| 3332 | 3332 |
|
| ... | ... |
@@ -3334,7 +3334,7 @@ Same as C<execute> method's C<sqlfilter> option. |
| 3334 | 3334 |
|
| 3335 | 3335 |
Table name. |
| 3336 | 3336 |
|
| 3337 |
-=item C<timestamp EXPERIMENTAL> |
|
| 3337 |
+=item C<timestamp> |
|
| 3338 | 3338 |
|
| 3339 | 3339 |
timestamp => 1 |
| 3340 | 3340 |
|
| ... | ... |
@@ -3394,7 +3394,7 @@ Create update parameter tag. |
| 3394 | 3394 |
|
| 3395 | 3395 |
set title = :title, author = :author |
| 3396 | 3396 |
|
| 3397 |
-=head2 C<insert_timestamp EXPERIMENTAL> |
|
| 3397 |
+=head2 C<update_timestamp> |
|
| 3398 | 3398 |
|
| 3399 | 3399 |
$dbi->update_timestamp(updated_at => sub { localtime });
|
| 3400 | 3400 |
|
| ... | ... |
@@ -3489,6 +3489,7 @@ L<DBIx::Custom> |
| 3489 | 3489 |
select method param option # will be removed at 2017/1/1 |
| 3490 | 3490 |
select method column option [COLUMN, as => ALIAS] format |
| 3491 | 3491 |
# will be removed at 2017/1/1 |
| 3492 |
+ execute method's sqlfilter option # will be removed at 2017/1/1 |
|
| 3492 | 3493 |
|
| 3493 | 3494 |
# Others |
| 3494 | 3495 |
execute("select * from {= title}"); # execute method's
|
| ... | ... |
@@ -108,7 +108,7 @@ sub _condition_to_sub {
|
| 108 | 108 |
|
| 109 | 109 |
=head1 NAME |
| 110 | 110 |
|
| 111 |
-DBIx::Custom::Mapper - Mapper of parameter EXPERIMENTAL |
|
| 111 |
+DBIx::Custom::Mapper - Mapper of parameter |
|
| 112 | 112 |
|
| 113 | 113 |
=head1 SYNOPSYS |
| 114 | 114 |
|
| ... | ... |
@@ -3085,6 +3085,24 @@ $rows = $dbi->select( |
| 3085 | 3085 |
)->all; |
| 3086 | 3086 |
is_deeply($rows, [{$key1 => 1}]);
|
| 3087 | 3087 |
|
| 3088 |
+test 'select() after_build_sql option'; |
|
| 3089 |
+$dbi = DBIx::Custom->connect; |
|
| 3090 |
+$dbi->user_table_info($user_table_info); |
|
| 3091 |
+eval { $dbi->execute("drop table $table1") };
|
|
| 3092 |
+$dbi->execute($create_table1); |
|
| 3093 |
+$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
|
|
| 3094 |
+$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
|
|
| 3095 |
+$rows = $dbi->select( |
|
| 3096 |
+ table => $table1, |
|
| 3097 |
+ column => $key1, |
|
| 3098 |
+ after_build_sql => sub {
|
|
| 3099 |
+ my $sql = shift; |
|
| 3100 |
+ $sql = "select * from ( $sql ) t where $key1 = 1"; |
|
| 3101 |
+ return $sql; |
|
| 3102 |
+ } |
|
| 3103 |
+)->all; |
|
| 3104 |
+is_deeply($rows, [{$key1 => 1}]);
|
|
| 3105 |
+ |
|
| 3088 | 3106 |
test 'dbi method from model'; |
| 3089 | 3107 |
$dbi = MyDBI9->connect; |
| 3090 | 3108 |
eval { $dbi->execute("drop table $table1") };
|