| ... | ... |
@@ -1,6 +1,6 @@ |
| 1 | 1 |
package DBIx::Custom; |
| 2 | 2 |
|
| 3 |
-our $VERSION = '0.1656'; |
|
| 3 |
+our $VERSION = '0.1657'; |
|
| 4 | 4 |
|
| 5 | 5 |
use 5.008001; |
| 6 | 6 |
use strict; |
| ... | ... |
@@ -1469,48 +1469,40 @@ Result class, default to L<DBIx::Custom::Result>. |
| 1469 | 1469 |
=head2 C<(experimental) safety_character> |
| 1470 | 1470 |
|
| 1471 | 1471 |
my $safety_character = $self->safety_character; |
| 1472 |
+ $dbi = $self->safety_character($character); |
|
| 1472 | 1473 |
|
| 1473 | 1474 |
Regex of safety character consist of table and column name, default to '\w'. |
| 1474 |
-Note that you don't have to specify like "[\w]". |
|
| 1475 |
+Note that you don't have to specify like '[\w]'. |
|
| 1475 | 1476 |
|
| 1476 | 1477 |
=head2 C<user> |
| 1477 | 1478 |
|
| 1478 | 1479 |
my $user = $dbi->user; |
| 1479 | 1480 |
$dbi = $dbi->user('Ken');
|
| 1480 | 1481 |
|
| 1481 |
-User name. |
|
| 1482 |
-C<connect()> method use this value to connect the database. |
|
| 1482 |
+User name, used when C<connect()> is executed. |
|
| 1483 | 1483 |
|
| 1484 | 1484 |
=head1 METHODS |
| 1485 | 1485 |
|
| 1486 | 1486 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
| 1487 |
-and use all method of L<DBI> |
|
| 1487 |
+and use all methods of L<DBI> |
|
| 1488 | 1488 |
and implements the following new ones. |
| 1489 | 1489 |
|
| 1490 | 1490 |
=head2 C<(experimental) apply_filter> |
| 1491 | 1491 |
|
| 1492 | 1492 |
$dbi->apply_filter( |
| 1493 |
- $table, |
|
| 1494 |
- $column1 => {in => $infilter1, out => $outfilter1, end => $endfilter1}
|
|
| 1495 |
- $column2 => {in => $infilter2, out => $outfilter2, end =. $endfilter2}
|
|
| 1493 |
+ 'book', |
|
| 1494 |
+ $column1 => {out => $outfilter1, in => $infilter1, end => $endfilter1}
|
|
| 1495 |
+ $column2 => {out => $outfilter2, in => $infilter2, end => $endfilter2}
|
|
| 1496 | 1496 |
..., |
| 1497 | 1497 |
); |
| 1498 | 1498 |
|
| 1499 |
-C<apply_filter> is automatically filter for columns of table. |
|
| 1500 |
-This have effect C<insert>, C<update>, C<delete>. C<select> |
|
| 1501 |
-and L<DBIx::Custom::Result> object. but this has'nt C<execute> method. |
|
| 1499 |
+Apply filter to specified column, C<out> is the direction from perl to database, |
|
| 1500 |
+C<in> is the direction from database to perl, |
|
| 1501 |
+C<end> is filter after C<in> filter. |
|
| 1502 | 1502 |
|
| 1503 |
-If you want to have effect C<execute()> method, use C<table> |
|
| 1504 |
-arguments. |
|
| 1505 |
- |
|
| 1506 |
- $result = $dbi->execute( |
|
| 1507 |
- "select * from table1 where {= key1} and {= key2};",
|
|
| 1508 |
- param => {key1 => 1, key2 => 2},
|
|
| 1509 |
- table => ['table1'] |
|
| 1510 |
- ); |
|
| 1511 |
- |
|
| 1512 |
-You can use three name as column name. |
|
| 1503 |
+You can use three column name to apply filter to column data. |
|
| 1513 | 1504 |
|
| 1505 |
+ (Example) |
|
| 1514 | 1506 |
1. column : author |
| 1515 | 1507 |
2. table.column : book.author |
| 1516 | 1508 |
3. table__column : book__author |
| ... | ... |
@@ -315,17 +315,37 @@ Following SQL is executed. |
| 315 | 315 |
Next example. |
| 316 | 316 |
|
| 317 | 317 |
my $result = $dbi->select( |
| 318 |
- table => 'book', |
|
| 319 |
- where => {'book.name' => 'Perl'},
|
|
| 320 |
- relation => {'book.id' => 'rental.book_id'}
|
|
| 318 |
+ table => 'book', |
|
| 319 |
+ column => ['company.name as company__name'] |
|
| 320 |
+ where => {'book.name' => 'Perl'},
|
|
| 321 |
+ join => ['left outer join company on book.company_id = company.id] |
|
| 321 | 322 |
); |
| 322 | 323 |
|
| 323 |
-C<relation> is relation of tables. This is inner join. |
|
| 324 |
+You can join table by C<join>. |
|
| 324 | 325 |
|
| 325 | 326 |
Following SQL is executed. |
| 326 | 327 |
|
| 327 |
- select * from book, rental where book.name = ? and book.id = rental.book_id; |
|
| 328 |
+ select company.name as company__name from book |
|
| 329 |
+ left outer join company on book.company_id = company.id |
|
| 330 |
+ where book.name = ?; |
|
| 331 |
+ |
|
| 332 |
+company_if of book and id of company is left outer joined. |
|
| 333 |
+ |
|
| 334 |
+Note that only when C<where> or C<column> contain table name, |
|
| 335 |
+C<join> is joined. |
|
| 336 |
+if you specify the following option, C<join> is not joined |
|
| 337 |
+because C<join> is not needed. |
|
| 328 | 338 |
|
| 339 |
+ my $result = $dbi->select( |
|
| 340 |
+ table => 'book', |
|
| 341 |
+ where => {'name' => 'Perl'},
|
|
| 342 |
+ join => ['left outer join company on book.company_id = company.id] |
|
| 343 |
+ ); |
|
| 344 |
+ |
|
| 345 |
+Following SQL is executeed. |
|
| 346 |
+ |
|
| 347 |
+ select * from book where book.name = ?; |
|
| 348 |
+ |
|
| 329 | 349 |
Next example. |
| 330 | 350 |
|
| 331 | 351 |
my $result = $dbi->select( |
| ... | ... |
@@ -1125,11 +1145,11 @@ This method is needed to be call after C<include_model()>. |
| 1125 | 1145 |
|
| 1126 | 1146 |
$dbi->setup_model; |
| 1127 | 1147 |
|
| 1128 |
-You can set C<relation> |
|
| 1148 |
+You can set C<join> |
|
| 1129 | 1149 |
|
| 1130 |
- $model->relation({'book.company_id' => 'company.id'});
|
|
| 1150 |
+ $model->join(['left outer join company on book.company_id = company.id']); |
|
| 1131 | 1151 |
|
| 1132 |
-This relation is used by C<select()>, C<select_at()> |
|
| 1152 |
+This C<join> is used by C<select()>, C<select_at()> |
|
| 1133 | 1153 |
|
| 1134 | 1154 |
=head2 Class name, Model name, Table name |
| 1135 | 1155 |
|
| ... | ... |
@@ -321,19 +321,36 @@ C<column>は列名、C<where>は条件です。 |
| 321 | 321 |
次のサンプルです。 |
| 322 | 322 |
|
| 323 | 323 |
my $result = $dbi->select( |
| 324 |
- table => 'book', |
|
| 325 |
- where => {book.name => 'Perl'},
|
|
| 326 |
- relation => {'book.id' => 'rental.book_id'}
|
|
| 324 |
+ table => 'book', |
|
| 325 |
+ column => ['company.name as company__name'] |
|
| 326 |
+ where => {'book.name' => 'Perl'},
|
|
| 327 |
+ join => ['left outer join company on book.company_id = company.id] |
|
| 327 | 328 |
); |
| 328 | 329 |
|
| 329 |
-C<relation>テーブル間の関係です。これは内部結合です。 |
|
| 330 |
+C<join>でテーブルの結合を行うことができます。 |
|
| 330 | 331 |
|
| 331 | 332 |
次のSQLが実行されます。 |
| 332 | 333 |
|
| 333 |
-bookテーブルのid列とrentalテーブルのbook_idが関連付けられます。 |
|
| 334 |
+ select company.name as company__name from book |
|
| 335 |
+ left outer join company on book.company_id = company.id |
|
| 336 |
+ where book.name = ?; |
|
| 337 |
+ |
|
| 338 |
+bookテーブルのcompany_id列とcompanyテーブルのidが左外部結合されます。 |
|
| 339 |
+次のSQLが実行されます。 |
|
| 340 |
+ |
|
| 341 |
+C<join>されるのは、C<where>やC<column>にテーブル名が含まれている |
|
| 342 |
+場合だけであることに注意してください。 |
|
| 343 |
+次のように指定した場合は結合の必要はないと判断されjoinはされません。 |
|
| 344 |
+ |
|
| 345 |
+ my $result = $dbi->select( |
|
| 346 |
+ table => 'book', |
|
| 347 |
+ where => {'name' => 'Perl'},
|
|
| 348 |
+ join => ['left outer join company on book.company_id = company.id] |
|
| 349 |
+ ); |
|
| 350 |
+ |
|
| 334 | 351 |
次のSQLが実行されます。 |
| 335 | 352 |
|
| 336 |
- select * from book, rental where book.name = ? and book.id = rental.book_id; |
|
| 353 |
+ select * from book where book.name = ?; |
|
| 337 | 354 |
|
| 338 | 355 |
次のサンプルです。 |
| 339 | 356 |
|
| ... | ... |
@@ -1162,11 +1179,11 @@ C<filter>でC<apply_filter()>で適用されるフィルタを定義しておく |
| 1162 | 1179 |
|
| 1163 | 1180 |
$dbi->setup_model; |
| 1164 | 1181 |
|
| 1165 |
-モデルにはリレーションを設定することもできます。 |
|
| 1182 |
+モデルにはC<join>を設定することもできます。 |
|
| 1166 | 1183 |
|
| 1167 |
- $model->relation({'book.company_id' => 'company.id'});
|
|
| 1184 |
+ $model->join(['left outer join company on book.company_id = company.id']); |
|
| 1168 | 1185 |
|
| 1169 |
-ここで設定したリレーションはC<select()>, C<select_at()>で利用されます。 |
|
| 1186 |
+ここで設定したC<join>はC<select()>, C<select_at()>で利用されます。 |
|
| 1170 | 1187 |
|
| 1171 | 1188 |
|
| 1172 | 1189 |
=head2 クラス名、モデル名、テーブル名 |