| ... | ... |
@@ -1,4 +1,5 @@ |
| 1 | 1 |
0.1691 |
| 2 |
+ - EXPERIMETAL column method and table_alias think about "-" separator |
|
| 2 | 3 |
- EXPERIMTANL column method think about separator |
| 3 | 4 |
- removed EXPERIMENTAL col method. |
| 4 | 5 |
- added EXPERIMENTAL separater method |
| ... | ... |
@@ -79,76 +79,6 @@ sub AUTOLOAD {
|
| 79 | 79 |
} |
| 80 | 80 |
} |
| 81 | 81 |
|
| 82 |
-sub apply_filter { shift->_apply_filter(@_) }
|
|
| 83 |
- |
|
| 84 |
-sub _apply_filter {
|
|
| 85 |
- my ($self, $table, @cinfos) = @_; |
|
| 86 |
- |
|
| 87 |
- # Initialize filters |
|
| 88 |
- $self->{filter} ||= {};
|
|
| 89 |
- $self->{filter}{out} ||= {};
|
|
| 90 |
- $self->{filter}{in} ||= {};
|
|
| 91 |
- $self->{filter}{end} ||= {};
|
|
| 92 |
- |
|
| 93 |
- # Usage |
|
| 94 |
- my $usage = "Usage: \$dbi->apply_filter(" .
|
|
| 95 |
- "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
|
|
| 96 |
- "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
|
|
| 97 |
- |
|
| 98 |
- # Apply filter |
|
| 99 |
- for (my $i = 0; $i < @cinfos; $i += 2) {
|
|
| 100 |
- |
|
| 101 |
- # Column |
|
| 102 |
- my $column = $cinfos[$i]; |
|
| 103 |
- if (ref $column eq 'ARRAY') {
|
|
| 104 |
- foreach my $c (@$column) {
|
|
| 105 |
- push @cinfos, $c, $cinfos[$i + 1]; |
|
| 106 |
- } |
|
| 107 |
- next; |
|
| 108 |
- } |
|
| 109 |
- |
|
| 110 |
- # Filter infomation |
|
| 111 |
- my $finfo = $cinfos[$i + 1] || {};
|
|
| 112 |
- croak "$usage (table: $table) " . _subname |
|
| 113 |
- unless ref $finfo eq 'HASH'; |
|
| 114 |
- foreach my $ftype (keys %$finfo) {
|
|
| 115 |
- croak "$usage (table: $table) " . _subname |
|
| 116 |
- unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; |
|
| 117 |
- } |
|
| 118 |
- |
|
| 119 |
- # Set filters |
|
| 120 |
- foreach my $way (qw/in out end/) {
|
|
| 121 |
- |
|
| 122 |
- # Filter |
|
| 123 |
- my $filter = $finfo->{$way};
|
|
| 124 |
- |
|
| 125 |
- # Filter state |
|
| 126 |
- my $state = !exists $finfo->{$way} ? 'not_exists'
|
|
| 127 |
- : !defined $filter ? 'not_defined' |
|
| 128 |
- : ref $filter eq 'CODE' ? 'code' |
|
| 129 |
- : 'name'; |
|
| 130 |
- |
|
| 131 |
- # Filter is not exists |
|
| 132 |
- next if $state eq 'not_exists'; |
|
| 133 |
- |
|
| 134 |
- # Check filter name |
|
| 135 |
- croak qq{Filter "$filter" is not registered } . _subname
|
|
| 136 |
- if $state eq 'name' |
|
| 137 |
- && ! exists $self->filters->{$filter};
|
|
| 138 |
- |
|
| 139 |
- # Set filter |
|
| 140 |
- my $f = $state eq 'not_defined' ? undef |
|
| 141 |
- : $state eq 'code' ? $filter |
|
| 142 |
- : $self->filters->{$filter};
|
|
| 143 |
- $self->{filter}{$way}{$table}{$column} = $f;
|
|
| 144 |
- $self->{filter}{$way}{$table}{"$table.$column"} = $f;
|
|
| 145 |
- $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
|
|
| 146 |
- } |
|
| 147 |
- } |
|
| 148 |
- |
|
| 149 |
- return $self; |
|
| 150 |
-} |
|
| 151 |
- |
|
| 152 | 82 |
sub assign_param {
|
| 153 | 83 |
my ($self, $param) = @_; |
| 154 | 84 |
|
| ... | ... |
@@ -375,14 +305,14 @@ sub create_model {
|
| 375 | 305 |
my $filter = ref $model->filter eq 'HASH' |
| 376 | 306 |
? [%{$model->filter}]
|
| 377 | 307 |
: $model->filter; |
| 378 |
- $self->apply_filter($model->table, @$filter); |
|
| 308 |
+ $self->_apply_filter($model->table, @$filter); |
|
| 379 | 309 |
my $result_filter = ref $model->result_filter eq 'HASH' |
| 380 | 310 |
? [%{$model->result_filter}]
|
| 381 | 311 |
: $model->result_filter; |
| 382 | 312 |
for (my $i = 1; $i < @$result_filter; $i += 2) {
|
| 383 | 313 |
$result_filter->[$i] = {in => $result_filter->[$i]};
|
| 384 | 314 |
} |
| 385 |
- $self->apply_filter($model->table, @$result_filter); |
|
| 315 |
+ $self->_apply_filter($model->table, @$result_filter); |
|
| 386 | 316 |
|
| 387 | 317 |
# Associate table with model |
| 388 | 318 |
croak "Table name is duplicated " . _subname |
| ... | ... |
@@ -478,6 +408,7 @@ sub execute {
|
| 478 | 408 |
my $filter_name_alias = $filter_name; |
| 479 | 409 |
$filter_name_alias =~ s/^$alias\./$table\./; |
| 480 | 410 |
$filter_name_alias =~ s/^${alias}__/${table}__/;
|
| 411 |
+ $filter_name_alias =~ s/^${alias}-/${table}-/;
|
|
| 481 | 412 |
$self->{filter}{$type}{$table}{$filter_name_alias}
|
| 482 | 413 |
= $self->{filter}{$type}{$alias}{$filter_name}
|
| 483 | 414 |
} |
| ... | ... |
@@ -1182,6 +1113,75 @@ sub where {
|
| 1182 | 1113 |
); |
| 1183 | 1114 |
} |
| 1184 | 1115 |
|
| 1116 |
+sub _apply_filter {
|
|
| 1117 |
+ my ($self, $table, @cinfos) = @_; |
|
| 1118 |
+ |
|
| 1119 |
+ # Initialize filters |
|
| 1120 |
+ $self->{filter} ||= {};
|
|
| 1121 |
+ $self->{filter}{out} ||= {};
|
|
| 1122 |
+ $self->{filter}{in} ||= {};
|
|
| 1123 |
+ $self->{filter}{end} ||= {};
|
|
| 1124 |
+ |
|
| 1125 |
+ # Usage |
|
| 1126 |
+ my $usage = "Usage: \$dbi->apply_filter(" .
|
|
| 1127 |
+ "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
|
|
| 1128 |
+ "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
|
|
| 1129 |
+ |
|
| 1130 |
+ # Apply filter |
|
| 1131 |
+ for (my $i = 0; $i < @cinfos; $i += 2) {
|
|
| 1132 |
+ |
|
| 1133 |
+ # Column |
|
| 1134 |
+ my $column = $cinfos[$i]; |
|
| 1135 |
+ if (ref $column eq 'ARRAY') {
|
|
| 1136 |
+ foreach my $c (@$column) {
|
|
| 1137 |
+ push @cinfos, $c, $cinfos[$i + 1]; |
|
| 1138 |
+ } |
|
| 1139 |
+ next; |
|
| 1140 |
+ } |
|
| 1141 |
+ |
|
| 1142 |
+ # Filter infomation |
|
| 1143 |
+ my $finfo = $cinfos[$i + 1] || {};
|
|
| 1144 |
+ croak "$usage (table: $table) " . _subname |
|
| 1145 |
+ unless ref $finfo eq 'HASH'; |
|
| 1146 |
+ foreach my $ftype (keys %$finfo) {
|
|
| 1147 |
+ croak "$usage (table: $table) " . _subname |
|
| 1148 |
+ unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; |
|
| 1149 |
+ } |
|
| 1150 |
+ |
|
| 1151 |
+ # Set filters |
|
| 1152 |
+ foreach my $way (qw/in out end/) {
|
|
| 1153 |
+ |
|
| 1154 |
+ # Filter |
|
| 1155 |
+ my $filter = $finfo->{$way};
|
|
| 1156 |
+ |
|
| 1157 |
+ # Filter state |
|
| 1158 |
+ my $state = !exists $finfo->{$way} ? 'not_exists'
|
|
| 1159 |
+ : !defined $filter ? 'not_defined' |
|
| 1160 |
+ : ref $filter eq 'CODE' ? 'code' |
|
| 1161 |
+ : 'name'; |
|
| 1162 |
+ |
|
| 1163 |
+ # Filter is not exists |
|
| 1164 |
+ next if $state eq 'not_exists'; |
|
| 1165 |
+ |
|
| 1166 |
+ # Check filter name |
|
| 1167 |
+ croak qq{Filter "$filter" is not registered } . _subname
|
|
| 1168 |
+ if $state eq 'name' |
|
| 1169 |
+ && ! exists $self->filters->{$filter};
|
|
| 1170 |
+ |
|
| 1171 |
+ # Set filter |
|
| 1172 |
+ my $f = $state eq 'not_defined' ? undef |
|
| 1173 |
+ : $state eq 'code' ? $filter |
|
| 1174 |
+ : $self->filters->{$filter};
|
|
| 1175 |
+ $self->{filter}{$way}{$table}{$column} = $f;
|
|
| 1176 |
+ $self->{filter}{$way}{$table}{"$table.$column"} = $f;
|
|
| 1177 |
+ $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
|
|
| 1178 |
+ $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
|
|
| 1179 |
+ } |
|
| 1180 |
+ } |
|
| 1181 |
+ |
|
| 1182 |
+ return $self; |
|
| 1183 |
+} |
|
| 1184 |
+ |
|
| 1185 | 1185 |
sub _create_bind_values {
|
| 1186 | 1186 |
my ($self, $params, $columns, $filter, $type) = @_; |
| 1187 | 1187 |
|
| ... | ... |
@@ -1424,6 +1424,17 @@ sub _where_to_obj {
|
| 1424 | 1424 |
return $obj; |
| 1425 | 1425 |
} |
| 1426 | 1426 |
|
| 1427 |
+# DEPRECATED! |
|
| 1428 |
+sub apply_filter {
|
|
| 1429 |
+ my $self = shift; |
|
| 1430 |
+ |
|
| 1431 |
+ warn "apply_filter is DEPRECATED! " . |
|
| 1432 |
+ "use type_rule method, DBIx::Custom::Result filter method, " . |
|
| 1433 |
+ "and DBIx::Custom::Model result_filter method instead"; |
|
| 1434 |
+ |
|
| 1435 |
+ return $self->_apply_filter(@_); |
|
| 1436 |
+} |
|
| 1437 |
+ |
|
| 1427 | 1438 |
# DEPRECATED! |
| 1428 | 1439 |
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1); |
| 1429 | 1440 |
sub select_at {
|
| ... | ... |
@@ -1544,19 +1555,18 @@ sub register_tag {
|
| 1544 | 1555 |
} |
| 1545 | 1556 |
|
| 1546 | 1557 |
# DEPRECATED! |
| 1547 |
-__PACKAGE__->attr('data_source');
|
|
| 1558 |
+has 'data_source'; |
|
| 1548 | 1559 |
|
| 1549 | 1560 |
# DEPRECATED! |
| 1550 |
-__PACKAGE__->attr( |
|
| 1551 |
- dbi_options => sub { {} },
|
|
| 1552 |
- filter_check => 1 |
|
| 1553 |
-); |
|
| 1561 |
+has dbi_options => sub { {} },
|
|
| 1562 |
+ filter_check => 1; |
|
| 1563 |
+ |
|
| 1554 | 1564 |
|
| 1555 | 1565 |
# DEPRECATED! |
| 1556 | 1566 |
sub default_bind_filter {
|
| 1557 | 1567 |
my $self = shift; |
| 1558 | 1568 |
|
| 1559 |
- warn "default_bind_filter is DEPRECATED! use apply_filter instead\n"; |
|
| 1569 |
+ warn "default_bind_filter is DEPRECATED!"; |
|
| 1560 | 1570 |
|
| 1561 | 1571 |
if (@_) {
|
| 1562 | 1572 |
my $fname = $_[0]; |
| ... | ... |
@@ -1580,7 +1590,7 @@ sub default_bind_filter {
|
| 1580 | 1590 |
sub default_fetch_filter {
|
| 1581 | 1591 |
my $self = shift; |
| 1582 | 1592 |
|
| 1583 |
- warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n"; |
|
| 1593 |
+ warn "default_fetch_filter is DEPRECATED!"; |
|
| 1584 | 1594 |
|
| 1585 | 1595 |
if (@_) {
|
| 1586 | 1596 |
my $fname = $_[0]; |
| ... | ... |
@@ -1696,6 +1706,7 @@ DBIx::Custom - Useful database access, respecting SQL! |
| 1696 | 1706 |
# Select |
| 1697 | 1707 |
my $result = $dbi->select( |
| 1698 | 1708 |
table => 'book', |
| 1709 |
+ column => ['title', 'author'], |
|
| 1699 | 1710 |
where => {author => 'Ken'},
|
| 1700 | 1711 |
); |
| 1701 | 1712 |
|
| ... | ... |
@@ -1703,8 +1714,8 @@ DBIx::Custom - Useful database access, respecting SQL! |
| 1703 | 1714 |
my $result = $dbi->select( |
| 1704 | 1715 |
table => 'book', |
| 1705 | 1716 |
column => [ |
| 1706 |
- 'book.author as book__author', |
|
| 1707 |
- 'company.name as company__name' |
|
| 1717 |
+ {book => [qw/title author/]},
|
|
| 1718 |
+ {company => ['name']}
|
|
| 1708 | 1719 |
], |
| 1709 | 1720 |
where => {'book.author' => 'Ken'},
|
| 1710 | 1721 |
join => ['left outer join company on book.company_id = company.id'], |
| ... | ... |
@@ -1897,7 +1908,7 @@ and implements the following new ones. |
| 1897 | 1908 |
|
| 1898 | 1909 |
Get available data type. |
| 1899 | 1910 |
|
| 1900 |
-=head2 C<apply_filter> |
|
| 1911 |
+=head2 C<apply_filter> DEPRECATED! |
|
| 1901 | 1912 |
|
| 1902 | 1913 |
$dbi->apply_filter( |
| 1903 | 1914 |
'book', |
| ... | ... |
@@ -1924,6 +1935,7 @@ Filter is applied to the follwoing tree column name pattern. |
| 1924 | 1935 |
1. Column : author |
| 1925 | 1936 |
2. Table.Column : book.author |
| 1926 | 1937 |
3. Table__Column : book__author |
| 1938 |
+ 4. Table-Column : book-author |
|
| 1927 | 1939 |
|
| 1928 | 1940 |
If column name is duplicate with other table, |
| 1929 | 1941 |
Main filter specified by C<table> option is used. |
| ... | ... |
@@ -1949,24 +1961,29 @@ Create assign parameter. |
| 1949 | 1961 |
|
| 1950 | 1962 |
This is equal to C<update_param> exept that set is not added. |
| 1951 | 1963 |
|
| 1952 |
-=head2 C<col> EXPERIMETNAL |
|
| 1964 |
+=head2 C<column> EXPERIMETNAL |
|
| 1953 | 1965 |
|
| 1954 |
- my $column = $model->col(book => ['author', 'title']); |
|
| 1966 |
+ my $column = $dbi->column(book => ['author', 'title']); |
|
| 1955 | 1967 |
|
| 1956 | 1968 |
Create column clause. The follwoing column clause is created. |
| 1957 | 1969 |
|
| 1958 | 1970 |
book.author as "book.author", |
| 1959 | 1971 |
book.title as "book.title" |
| 1960 | 1972 |
|
| 1961 |
-=head2 C<column> EXPERIMETNAL |
|
| 1962 |
- |
|
| 1963 |
- my $column = $dbi->column(book => ['author', 'title']); |
|
| 1973 |
+You can change separator by C<separator> method. |
|
| 1964 | 1974 |
|
| 1965 |
-Create column clause. The follwoing column clause is created. |
|
| 1966 |
- |
|
| 1967 |
- book.author as book__author, |
|
| 1968 |
- book.title as book__title |
|
| 1975 |
+ # Separator is double underbar |
|
| 1976 |
+ $dbi->separator('__');
|
|
| 1977 |
+ |
|
| 1978 |
+ book.author as "book__author", |
|
| 1979 |
+ book.title as "book__title" |
|
| 1969 | 1980 |
|
| 1981 |
+ # Separator is hyphen |
|
| 1982 |
+ $dbi->separator('-');
|
|
| 1983 |
+ |
|
| 1984 |
+ book.author as "book-author", |
|
| 1985 |
+ book.title as "book-title" |
|
| 1986 |
+ |
|
| 1970 | 1987 |
=head2 C<connect> |
| 1971 | 1988 |
|
| 1972 | 1989 |
my $dbi = DBIx::Custom->connect( |
| ... | ... |
@@ -2433,14 +2450,57 @@ Register filters, used by C<filter> option of many methods. |
| 2433 | 2450 |
|
| 2434 | 2451 |
Filtering rule when data is send into and get from database. |
| 2435 | 2452 |
This has a little complex problem. |
| 2453 |
+ |
|
| 2436 | 2454 |
In C<into> you can specify type name as same as type name defined |
| 2437 | 2455 |
by create table, such as C<DATETIME> or C<DATE>. |
| 2438 |
-but in C<from> you can't specify type name defined by create table. |
|
| 2456 |
+Type rule of C<into> is enabled on the following pattern. |
|
| 2457 |
+ |
|
| 2458 |
+=over 4 |
|
| 2459 |
+ |
|
| 2460 |
+=item 1. column name |
|
| 2461 |
+ |
|
| 2462 |
+ issue_date |
|
| 2463 |
+ issue_datetime |
|
| 2464 |
+ |
|
| 2465 |
+=item 2. table name and column name, separator is dot |
|
| 2466 |
+ |
|
| 2467 |
+ book.issue_date |
|
| 2468 |
+ book.issue_datetime |
|
| 2469 |
+ |
|
| 2470 |
+=back |
|
| 2471 |
+ |
|
| 2472 |
+In C<from> you can't specify type name defined by create table. |
|
| 2439 | 2473 |
You must specify data type, this is internal one. |
| 2440 | 2474 |
You get all data type by C<available_data_type>. |
| 2441 | 2475 |
|
| 2442 | 2476 |
print $dbi->available_data_type; |
| 2443 | 2477 |
|
| 2478 |
+Type rule of C<from> is enabled on the following pattern. |
|
| 2479 |
+ |
|
| 2480 |
+=item 1. column name |
|
| 2481 |
+ |
|
| 2482 |
+ issue_date |
|
| 2483 |
+ issue_datetime |
|
| 2484 |
+ |
|
| 2485 |
+=item 2. table name and column name, separator is dot |
|
| 2486 |
+ |
|
| 2487 |
+ book.issue_date |
|
| 2488 |
+ book.issue_datetime |
|
| 2489 |
+ |
|
| 2490 |
+=item 3. table name and column name, separator is double underbar |
|
| 2491 |
+ |
|
| 2492 |
+ book__issue_date |
|
| 2493 |
+ book__issue_datetime |
|
| 2494 |
+ |
|
| 2495 |
+=item 4. table name and column name, separator is hyphen |
|
| 2496 |
+ |
|
| 2497 |
+ book-issue_date |
|
| 2498 |
+ book-issue_datetime |
|
| 2499 |
+ |
|
| 2500 |
+This is useful in HTML. |
|
| 2501 |
+ |
|
| 2502 |
+=back |
|
| 2503 |
+ |
|
| 2444 | 2504 |
You can also specify multiple types |
| 2445 | 2505 |
|
| 2446 | 2506 |
$dbi->type_rule( |
| ... | ... |
@@ -2565,7 +2625,7 @@ join clausees needed when SQL is created is used automatically. |
| 2565 | 2625 |
|
| 2566 | 2626 |
$dbi->select( |
| 2567 | 2627 |
table => 'book', |
| 2568 |
- column => ['company.location_id as company__location_id'], |
|
| 2628 |
+ column => ['company.location_id as location_id'], |
|
| 2569 | 2629 |
where => {'company.name' => 'Orange'},
|
| 2570 | 2630 |
join => [ |
| 2571 | 2631 |
'left outer join company on book.company_id = company.id', |
| ... | ... |
@@ -2576,10 +2636,10 @@ join clausees needed when SQL is created is used automatically. |
| 2576 | 2636 |
In above select, column and where clause contain "company" table, |
| 2577 | 2637 |
the following SQL is created |
| 2578 | 2638 |
|
| 2579 |
- select company.location_id as company__location_id |
|
| 2639 |
+ select company.location_id as location_id |
|
| 2580 | 2640 |
from book |
| 2581 | 2641 |
left outer join company on book.company_id = company.id |
| 2582 |
- where company.name = Orange |
|
| 2642 |
+ where company.name = ?; |
|
| 2583 | 2643 |
|
| 2584 | 2644 |
=item C<primary_key> |
| 2585 | 2645 |
|
| ... | ... |
@@ -574,8 +574,9 @@ Generally Class name is model name, and table name is model name. |
| 574 | 574 |
You can change model name. |
| 575 | 575 |
|
| 576 | 576 |
package MyModel::book; |
| 577 |
+ use MyModel -base; |
|
| 577 | 578 |
|
| 578 |
- __PACAKGE__->attr(name => 'book_model'); |
|
| 579 |
+ has name => 'book_model'; |
|
| 579 | 580 |
|
| 580 | 581 |
CLASS MODEL TABLE |
| 581 | 582 |
book book_model (MODEL) -> book_model |
| ... | ... |
@@ -587,8 +588,9 @@ Model name is the name used by L<model> of L<DBIx::Custom>. |
| 587 | 588 |
You can change table name. |
| 588 | 589 |
|
| 589 | 590 |
package MyModel::book; |
| 591 |
+ use MyModel -base; |
|
| 590 | 592 |
|
| 591 |
- __PACAKGE__->attr(table => 'book_table'); |
|
| 593 |
+ has table => 'book_table'; |
|
| 592 | 594 |
|
| 593 | 595 |
CLASS MODEL TABLE |
| 594 | 596 |
book (CLASS) -> book book_table |
| ... | ... |
@@ -602,7 +604,7 @@ Table name is the table really accessed. |
| 602 | 604 |
To create column clause automatically, use C<mycolumn>. |
| 603 | 605 |
Valude of C<table> and C<columns> is used. |
| 604 | 606 |
|
| 605 |
- my $column_clause = $model->mycolumn; |
|
| 607 |
+ my $mycolumns = $model->mycolumn; |
|
| 606 | 608 |
|
| 607 | 609 |
If C<table> is 'book'AC<column> is ['id', 'name'], |
| 608 | 610 |
the following clause is created. |
| ... | ... |
@@ -613,34 +615,12 @@ These column name is for removing column name ambiguities. |
| 613 | 615 |
|
| 614 | 616 |
You can create column clause from columns of other table. |
| 615 | 617 |
|
| 616 |
- my $column_clause = $model->column('company');
|
|
| 618 |
+ my $columns = $model->column('company');
|
|
| 617 | 619 |
|
| 618 |
-If C<table> is 'company'AC<column> is ['id', 'name'], |
|
| 620 |
+If C<table> is "company", C<column> return ['id', 'name'], |
|
| 619 | 621 |
the following clause is created. |
| 620 | 622 |
|
| 621 |
- company.id as company__id, company.name as company__name |
|
| 622 |
- |
|
| 623 |
-=head2 Create column clause automatically : column_clause |
|
| 624 |
- |
|
| 625 |
-To create column clause automatically, use C<column_clause>. |
|
| 626 |
-Valude of C<table> and C<columns> is used. |
|
| 627 |
- |
|
| 628 |
- my $column_clause = $model->column_clause; |
|
| 629 |
- |
|
| 630 |
-If C<table> is 'book'AC<column> is ['id', 'name'], |
|
| 631 |
-the following clause is created. |
|
| 632 |
- |
|
| 633 |
- book.id as id, book.name as name |
|
| 634 |
- |
|
| 635 |
-These column name is for removing column name ambiguities. |
|
| 636 |
- |
|
| 637 |
-If you remove some columns, use C<remove> option. |
|
| 638 |
- |
|
| 639 |
- my $column_clause = $model->column_clause(remove => ['id']); |
|
| 640 |
- |
|
| 641 |
-If you add some column, use C<add> option. |
|
| 642 |
- |
|
| 643 |
- my $column_clause = $model->column_clause(add => ['company.id as company__id']); |
|
| 623 |
+ company.id as "company.id", company.name as "company.name" |
|
| 644 | 624 |
|
| 645 | 625 |
=head2 Model Examples |
| 646 | 626 |
|
| ... | ... |
@@ -228,24 +228,12 @@ and implements the following new ones. |
| 228 | 228 |
my $column = $model->column(book => ['author', 'title']); |
| 229 | 229 |
my $column = $model->column('book');
|
| 230 | 230 |
|
| 231 |
-Create column clause. The follwoing column clause is created. |
|
| 232 |
- |
|
| 233 |
- book.author as book__author, |
|
| 234 |
- book.title as book__title |
|
| 235 |
- |
|
| 236 |
-If column names is omitted, C<columns> attribute of the model is used. |
|
| 237 |
- |
|
| 238 |
-=head2 C<col> EXPERIMETNAL |
|
| 239 |
- |
|
| 240 |
- my $column = $model->col(book => ['author', 'title']); |
|
| 241 |
- my $column = $model->col('book');
|
|
| 242 |
- |
|
| 243 | 231 |
Create column clause. The follwoing column clause is created. |
| 244 | 232 |
|
| 245 | 233 |
book.author as "book.author", |
| 246 | 234 |
book.title as "book.title" |
| 247 | 235 |
|
| 248 |
-If column names is omitted, C<columns> attribute of the model is used. |
|
| 236 |
+If Second argument is ommited, all columns set by C<columns> is used. |
|
| 249 | 237 |
|
| 250 | 238 |
=head2 C<delete> |
| 251 | 239 |
|
| ... | ... |
@@ -1,5 +1,4 @@ |
| 1 | 1 |
package DBIx::Custom::Query; |
| 2 |
- |
|
| 3 | 2 |
use Object::Simple -base; |
| 4 | 3 |
|
| 5 | 4 |
use Carp 'croak'; |
| ... | ... |
@@ -60,7 +59,7 @@ sub filter {
|
| 60 | 59 |
} |
| 61 | 60 |
|
| 62 | 61 |
# DEPRECATED! |
| 63 |
-__PACKAGE__->attr('default_filter');
|
|
| 62 |
+has 'default_filter'; |
|
| 64 | 63 |
|
| 65 | 64 |
1; |
| 66 | 65 |
|
| ... | ... |
@@ -89,7 +89,7 @@ sub _parse_parameter {
|
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 | 91 |
# DEPRECATED! |
| 92 |
-__PACKAGE__->attr('tags' => sub { {} });
|
|
| 92 |
+has tags => sub { {} };
|
|
| 93 | 93 |
|
| 94 | 94 |
# DEPRECATED! |
| 95 | 95 |
sub register_tag {
|
| ... | ... |
@@ -335,7 +335,7 @@ sub _parse_tag {
|
| 335 | 335 |
} |
| 336 | 336 |
|
| 337 | 337 |
# DEPRECATED! |
| 338 |
-__PACKAGE__->attr('tag_processors' => sub { {} });
|
|
| 338 |
+has tag_processors => sub { {} };
|
|
| 339 | 339 |
|
| 340 | 340 |
# DEPRECATED! |
| 341 | 341 |
sub register_tag_processor {
|
| ... | ... |
@@ -116,7 +116,7 @@ sub fetch {
|
| 116 | 116 |
my $column = $columns->[$i]; |
| 117 | 117 |
my $f = exists $filter->{$column}
|
| 118 | 118 |
? $filter->{$column}
|
| 119 |
- : $self->default_filter; |
|
| 119 |
+ : $self->_default_filter; |
|
| 120 | 120 |
my $ef = $end_filter->{$column};
|
| 121 | 121 |
|
| 122 | 122 |
# Filtering |
| ... | ... |
@@ -186,7 +186,7 @@ sub fetch_hash {
|
| 186 | 186 |
my $column = $columns->[$i]; |
| 187 | 187 |
my $f = exists $filter->{$column}
|
| 188 | 188 |
? $filter->{$column}
|
| 189 |
- : $self->default_filter; |
|
| 189 |
+ : $self->_default_filter; |
|
| 190 | 190 |
my $ef = $end_filter->{$column};
|
| 191 | 191 |
|
| 192 | 192 |
# Filtering |
| ... | ... |
@@ -266,25 +266,39 @@ sub fetch_multi {
|
| 266 | 266 |
|
| 267 | 267 |
*one = \&fetch_hash_first; |
| 268 | 268 |
|
| 269 |
+# DEPRECATED! |
|
| 269 | 270 |
sub remove_end_filter {
|
| 270 | 271 |
my $self = shift; |
| 271 | 272 |
|
| 273 |
+ warn "remove_end_filter is DEPRECATED! use filter_off attribute instead"; |
|
| 274 |
+ |
|
| 272 | 275 |
$self->{end_filter} = {};
|
| 273 | 276 |
|
| 274 | 277 |
return $self; |
| 275 | 278 |
} |
| 276 | 279 |
|
| 280 |
+# DEPRECATED! |
|
| 277 | 281 |
sub remove_filter {
|
| 278 | 282 |
my $self = shift; |
| 283 |
+ |
|
| 284 |
+ warn "remove_filter is DEPRECATED! use filter_off attribute instead"; |
|
| 279 | 285 |
|
| 280 | 286 |
$self->{filter} = {};
|
| 281 | 287 |
|
| 282 | 288 |
return $self; |
| 283 | 289 |
} |
| 284 | 290 |
|
| 285 |
-# Deprecated |
|
| 291 |
+# DEPRECATED! |
|
| 286 | 292 |
sub default_filter {
|
| 287 | 293 |
my $self = shift; |
| 294 |
+ warn "default_filter is DEPRECATED!"; |
|
| 295 |
+ return $self->_default_filter(@_) |
|
| 296 |
+} |
|
| 297 |
+ |
|
| 298 |
+# DEPRECATED! |
|
| 299 |
+sub _default_filter {
|
|
| 300 |
+ my $self = shift; |
|
| 301 |
+ |
|
| 288 | 302 |
|
| 289 | 303 |
if (@_) {
|
| 290 | 304 |
my $fname = $_[0]; |
| ... | ... |
@@ -305,7 +319,7 @@ sub default_filter {
|
| 305 | 319 |
} |
| 306 | 320 |
|
| 307 | 321 |
# DEPRECATED! |
| 308 |
-__PACKAGE__->attr('filter_check');
|
|
| 322 |
+has 'filter_check'; |
|
| 309 | 323 |
|
| 310 | 324 |
1; |
| 311 | 325 |
|
| ... | ... |
@@ -489,7 +503,7 @@ L<DBIx::Custom>. |
| 489 | 503 |
|
| 490 | 504 |
This is alias for C<fetch_hash_first>. |
| 491 | 505 |
|
| 492 |
-=head2 C<remove_end_filter> |
|
| 506 |
+=head2 C<remove_end_filter> DEPRECATED! |
|
| 493 | 507 |
|
| 494 | 508 |
$result->remove_end_filter; |
| 495 | 509 |
|
| ... | ... |
@@ -6,7 +6,7 @@ use utf8; |
| 6 | 6 |
use Encode qw/encode_utf8 decode_utf8/; |
| 7 | 7 |
use Data::Dumper; |
| 8 | 8 |
|
| 9 |
-$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
|
|
| 9 |
+#$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
|
|
| 10 | 10 |
|
| 11 | 11 |
BEGIN {
|
| 12 | 12 |
eval { require DBD::SQLite; 1 }
|
| ... | ... |
@@ -2187,6 +2187,26 @@ $result = $model->select( |
| 2187 | 2187 |
is_deeply($result->one, |
| 2188 | 2188 |
{'table2_alias.key1' => 1, 'table2_alias.key3' => 48});
|
| 2189 | 2189 |
|
| 2190 |
+$dbi->separator('__');
|
|
| 2191 |
+$result = $model->select( |
|
| 2192 |
+ column => [ |
|
| 2193 |
+ $model->column('table2_alias')
|
|
| 2194 |
+ ], |
|
| 2195 |
+ where => {'table2_alias.key3' => 2}
|
|
| 2196 |
+); |
|
| 2197 |
+is_deeply($result->one, |
|
| 2198 |
+ {'table2_alias__key1' => 1, 'table2_alias__key3' => 48});
|
|
| 2199 |
+ |
|
| 2200 |
+$dbi->separator('-');
|
|
| 2201 |
+$result = $model->select( |
|
| 2202 |
+ column => [ |
|
| 2203 |
+ $model->column('table2_alias')
|
|
| 2204 |
+ ], |
|
| 2205 |
+ where => {'table2_alias.key3' => 2}
|
|
| 2206 |
+); |
|
| 2207 |
+is_deeply($result->one, |
|
| 2208 |
+ {'table2_alias-key1' => 1, 'table2_alias-key3' => 48});
|
|
| 2209 |
+ |
|
| 2190 | 2210 |
test 'type() option'; |
| 2191 | 2211 |
$dbi = DBIx::Custom->connect( |
| 2192 | 2212 |
data_source => 'dbi:SQLite:dbname=:memory:', |
| ... | ... |
@@ -2768,6 +2788,19 @@ is_deeply($result->one, |
| 2768 | 2788 |
{key1 => 2, key2 => 2, 'table2__key1' => 3, 'table2__key3' => 9});
|
| 2769 | 2789 |
is_deeply($model2->select->one, {key1 => 3, key3 => 9});
|
| 2770 | 2790 |
|
| 2791 |
+$dbi->separator('-');
|
|
| 2792 |
+$model = $dbi->model('table1');
|
|
| 2793 |
+$result = $model->select( |
|
| 2794 |
+ column => [ |
|
| 2795 |
+ $model->mycolumn, |
|
| 2796 |
+ {table2 => [qw/key1 key3/]}
|
|
| 2797 |
+ ], |
|
| 2798 |
+ where => {'table1.key1' => 1}
|
|
| 2799 |
+); |
|
| 2800 |
+is_deeply($result->one, |
|
| 2801 |
+ {key1 => 2, key2 => 2, 'table2-key1' => 3, 'table2-key3' => 9});
|
|
| 2802 |
+is_deeply($model2->select->one, {key1 => 3, key3 => 9});
|
|
| 2803 |
+ |
|
| 2771 | 2804 |
|
| 2772 | 2805 |
test 'filter_off'; |
| 2773 | 2806 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
| ... | ... |
@@ -1,5 +1,4 @@ |
| 1 | 1 |
package MyModel8; |
| 2 |
- |
|
| 3 |
-use base 'DBIx::Custom::Model'; |
|
| 2 |
+use DBIx::Custom::Model -base; |
|
| 4 | 3 |
|
| 5 | 4 |
1; |
| ... | ... |
@@ -1,10 +1,8 @@ |
| 1 | 1 |
package MyModel8::table1; |
| 2 |
+use MyModel8 -base; |
|
| 2 | 3 |
|
| 3 |
-use base 'MyModel8'; |
|
| 4 |
- |
|
| 5 |
-__PACKAGE__->attr(join => sub { ['left join table2 as table2_alias on table1.key1 = table2_alias.key1'] });
|
|
| 6 |
- |
|
| 7 |
-__PACKAGE__->attr(table_alias => sub { {'table2_alias' => 'table2'} });
|
|
| 4 |
+has join => sub { ['left join table2 as table2_alias on table1.key1 = table2_alias.key1'] };
|
|
| 5 |
+has table_alias => sub { {'table2_alias' => 'table2'} };
|
|
| 8 | 6 |
|
| 9 | 7 |
|
| 10 | 8 |
1; |
| ... | ... |
@@ -1,11 +1,10 @@ |
| 1 | 1 |
package MyModel8::table2; |
| 2 |
+use MyModel8 -base; |
|
| 2 | 3 |
|
| 3 |
-use base 'MyModel8'; |
|
| 4 |
- |
|
| 5 |
-__PACKAGE__->attr(filter => sub {
|
|
| 4 |
+has filter => sub {
|
|
| 6 | 5 |
{
|
| 7 | 6 |
key3 => {out => sub { $_[0] * 2}, in => sub { $_[0] * 3}, end => sub { $_[0] * 4 }}
|
| 8 | 7 |
} |
| 9 |
-}); |
|
| 8 |
+}; |
|
| 10 | 9 |
|
| 11 | 10 |
1; |