cleanup
|
1 |
package DBIx::Custom; |
2 | ||
DBIx::Custom::Model select()...
|
3 |
our $VERSION = '0.1649'; |
fixed DBIx::Custom::QueryBui...
|
4 | |
5 |
use 5.008001; |
|
cleanup
|
6 |
use strict; |
7 |
use warnings; |
|
8 | ||
remove run_transaction().
|
9 |
use base 'Object::Simple'; |
many change
|
10 | |
packaging one directory
|
11 |
use Carp 'croak'; |
12 |
use DBI; |
|
13 |
use DBIx::Custom::Result; |
|
cleanup
|
14 |
use DBIx::Custom::Query; |
cleanup
|
15 |
use DBIx::Custom::QueryBuilder; |
added experimental DBIx::Cus...
|
16 |
use DBIx::Custom::Where; |
add feture. all model class ...
|
17 |
use DBIx::Custom::Model; |
cleanup
|
18 |
use DBIx::Custom::Tag; |
update document
|
19 |
use Encode qw/encode_utf8 decode_utf8/; |
packaging one directory
|
20 | |
fix tests
|
21 |
__PACKAGE__->attr( |
added experimental DBIx::Cus...
|
22 |
[qw/data_source dbh password user/], |
fix tests
|
23 |
cache => 1, |
add default_dbi_option()
|
24 |
dbi_option => sub { {} }, |
25 |
default_dbi_option => sub {{ |
|
26 |
RaiseError => 1, |
|
27 |
PrintError => 0, |
|
28 |
AutoCommit => 1 |
|
29 |
}}, |
|
add models() attribute
|
30 |
models => sub { {} }, |
cleanup
|
31 |
query_builder => sub { DBIx::Custom::QueryBuilder->new }, |
many changed
|
32 |
result_class => 'DBIx::Custom::Result', |
update pod
|
33 |
safety_column_name => sub { qr/^[\w\.]*$/ }, |
34 |
stash => sub { {} } |
|
many changed
|
35 |
); |
36 | ||
37 |
__PACKAGE__->attr( |
|
38 |
cache_method => sub { |
|
39 |
sub { |
|
40 |
my $self = shift; |
|
41 |
|
|
42 |
$self->{_cached} ||= {}; |
|
43 |
|
|
44 |
if (@_ > 1) { |
|
45 |
$self->{_cached}{$_[0]} = $_[1] |
|
46 |
} |
|
47 |
else { |
|
48 |
return $self->{_cached}{$_[0]} |
|
49 |
} |
|
50 |
} |
|
51 |
} |
|
52 |
); |
|
53 | ||
54 |
__PACKAGE__->attr( |
|
fix tests
|
55 |
filters => sub { |
56 |
{ |
|
57 |
encode_utf8 => sub { encode_utf8($_[0]) }, |
|
58 |
decode_utf8 => sub { decode_utf8($_[0]) } |
|
59 |
} |
|
many changed
|
60 |
} |
fix tests
|
61 |
); |
cleanup
|
62 | |
added helper method
|
63 |
our $AUTOLOAD; |
64 |
sub AUTOLOAD { |
|
65 |
my $self = shift; |
|
66 | ||
renamed helper to method.
|
67 |
# Method name |
68 |
my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/; |
|
added helper method
|
69 | |
renamed helper to method.
|
70 |
# Method |
71 |
$self->{_methods} ||= {}; |
|
add feture. all model class ...
|
72 |
if (my $method = $self->{_methods}->{$mname}) { |
73 |
return $self->$method(@_) |
|
74 |
} |
|
75 |
elsif ($self->dbh->can($mname)) { |
|
76 |
$self->dbh->$mname(@_); |
|
77 |
} |
|
78 |
else { |
|
79 |
croak qq/Can't locate object method "$mname" via "$package"/ |
|
80 |
} |
|
added helper method
|
81 |
} |
82 | ||
renamed auto_filter to apply...
|
83 |
sub apply_filter { |
many changed
|
84 |
my ($self, $table, @cinfos) = @_; |
85 | ||
86 |
# Initialize filters |
|
cleanup
|
87 |
$self->{filter} ||= {}; |
many changed
|
88 |
$self->{filter}{out} ||= {}; |
89 |
$self->{filter}{in} ||= {}; |
|
cleanup
|
90 |
|
many changed
|
91 |
# Create filters |
92 |
my $usage = "Usage: \$dbi->apply_filter(" . |
|
fix bug : filter can't over...
|
93 |
"TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " . |
94 |
"COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)"; |
|
many changed
|
95 | |
96 |
for (my $i = 0; $i < @cinfos; $i += 2) { |
|
added auto_filter method
|
97 |
|
many changed
|
98 |
# Column |
99 |
my $column = $cinfos[$i]; |
|
added auto_filter method
|
100 |
|
fix bug : filter can't over...
|
101 |
# Filter info |
102 |
my $finfo = $cinfos[$i + 1] || {}; |
|
103 |
croak $usage unless ref $finfo eq 'HASH'; |
|
104 |
foreach my $ftype (keys %$finfo) { |
|
105 |
croak $usage unless $ftype eq 'in' || $ftype eq 'out' |
|
106 |
|| $ftype eq 'end'; |
|
many changed
|
107 |
} |
108 |
|
|
fix bug : filter can't over...
|
109 |
foreach my $way (qw/in out end/) { |
110 |
my $filter = $finfo->{$way}; |
|
cleanup
|
111 |
|
fix bug : filter can't over...
|
112 |
# State |
113 |
my $state = !exists $finfo->{$way} ? 'not_exists' |
|
114 |
: !defined $filter ? 'not_defined' |
|
115 |
: ref $filter eq 'CODE' ? 'code' |
|
116 |
: 'name'; |
|
117 |
|
|
118 |
next if $state eq 'not_exists'; |
|
119 |
|
|
120 |
# Check filter |
|
121 |
croak qq{Filter "$filter" is not registered} |
|
122 |
if $state eq 'name' |
|
123 |
&& ! exists $self->filters->{$filter}; |
|
124 |
|
|
125 |
# Filter |
|
126 |
my $f = $state eq 'not_defined' ? undef |
|
127 |
: $state eq 'code' ? $filter |
|
128 |
: $self->filters->{$filter}; |
|
129 |
$self->{filter}{$way}{$table}{$column} = $f; |
|
130 |
$self->{filter}{$way}{$table}{"$table.$column"} = $f; |
|
131 |
$self->{filter}{$way}{$table}{"${table}__$column"} = $f; |
|
many changed
|
132 |
} |
added auto_filter method
|
133 |
} |
134 |
|
|
many changed
|
135 |
return $self; |
added auto_filter method
|
136 |
} |
137 | ||
renamed helper to method.
|
138 |
sub method { |
added helper method
|
139 |
my $self = shift; |
140 |
|
|
141 |
# Merge |
|
renamed helper to method.
|
142 |
my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
143 |
$self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
added helper method
|
144 |
|
145 |
return $self; |
|
146 |
} |
|
147 | ||
packaging one directory
|
148 |
sub connect { |
cleanup
|
149 |
my $self = ref $_[0] ? shift : shift->new(@_);; |
removed register_format()
|
150 |
|
many changed
|
151 |
# Attributes |
packaging one directory
|
152 |
my $data_source = $self->data_source; |
many changed
|
153 |
croak qq{"data_source" must be specified to connect()"} |
check arguments of connect m...
|
154 |
unless $data_source; |
packaging one directory
|
155 |
my $user = $self->user; |
156 |
my $password = $self->password; |
|
renamed dbi_options to dbi_o...
|
157 |
my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}}; |
added dbi_options attribute
|
158 |
|
update document
|
159 |
# Connect |
select, insert, update, upda...
|
160 |
my $dbh = eval {DBI->connect( |
packaging one directory
|
161 |
$data_source, |
162 |
$user, |
|
163 |
$password, |
|
164 |
{ |
|
add default_dbi_option()
|
165 |
%{$self->default_dbi_option}, |
renamed dbi_options to dbi_o...
|
166 |
%$dbi_option |
packaging one directory
|
167 |
} |
168 |
)}; |
|
169 |
|
|
update document
|
170 |
# Connect error |
packaging one directory
|
171 |
croak $@ if $@; |
172 |
|
|
update document
|
173 |
# Database handle |
packaging one directory
|
174 |
$self->dbh($dbh); |
update document
|
175 |
|
packaging one directory
|
176 |
return $self; |
177 |
} |
|
178 | ||
cleanup
|
179 |
sub create_query { |
180 |
my ($self, $source) = @_; |
|
update document
|
181 |
|
cleanup
|
182 |
# Cache |
183 |
my $cache = $self->cache; |
|
update document
|
184 |
|
cleanup
|
185 |
# Create query |
186 |
my $query; |
|
187 |
if ($cache) { |
|
188 |
|
|
189 |
# Get query |
|
190 |
my $q = $self->cache_method->($self, $source); |
|
191 |
|
|
192 |
# Create query |
|
add table tag
|
193 |
if ($q) { |
194 |
$query = DBIx::Custom::Query->new($q); |
|
195 |
$query->filters($self->filters); |
|
196 |
} |
|
cleanup
|
197 |
} |
198 |
|
|
199 |
unless ($query) { |
|
cleanup insert
|
200 | |
cleanup
|
201 |
# Create SQL object |
202 |
my $builder = $self->query_builder; |
|
203 |
|
|
204 |
# Create query |
|
205 |
$query = $builder->build_query($source); |
|
removed register_format()
|
206 | |
cleanup
|
207 |
# Cache query |
208 |
$self->cache_method->($self, $source, |
|
209 |
{sql => $query->sql, |
|
add table tag
|
210 |
columns => $query->columns, |
211 |
tables => $query->tables}) |
|
cleanup
|
212 |
if $cache; |
cleanup insert
|
213 |
} |
214 |
|
|
cleanup
|
215 |
# Prepare statement handle |
216 |
my $sth; |
|
217 |
eval { $sth = $self->dbh->prepare($query->{sql})}; |
|
renamed DBIx::Custom::TagPro...
|
218 |
$self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@; |
packaging one directory
|
219 |
|
cleanup
|
220 |
# Set statement handle |
221 |
$query->sth($sth); |
|
packaging one directory
|
222 |
|
cleanup
|
223 |
# Set filters |
224 |
$query->filters($self->filters); |
|
225 |
|
|
cleanup
|
226 |
return $query; |
packaging one directory
|
227 |
} |
228 | ||
cleanup
|
229 |
our %VALID_DELETE_ARGS |
added experimental sugar met...
|
230 |
= map { $_ => 1 } qw/table where append filter allow_delete_all query/; |
cleanup update and update_al...
|
231 | |
cleanup
|
232 |
sub delete { |
select, insert, update, upda...
|
233 |
my ($self, %args) = @_; |
cleanup update and update_al...
|
234 |
|
235 |
# Check arguments |
|
select, insert, update, upda...
|
236 |
foreach my $name (keys %args) { |
add tests
|
237 |
croak qq{"$name" is invalid argument} |
cleanup
|
238 |
unless $VALID_DELETE_ARGS{$name}; |
cleanup update and update_al...
|
239 |
} |
240 |
|
|
241 |
# Arguments |
|
select, insert, update, upda...
|
242 |
my $table = $args{table} || ''; |
added table not specified ex...
|
243 |
croak qq{"table" option must be specified} unless $table; |
select, insert, update, upda...
|
244 |
my $where = $args{where} || {}; |
select() where can't receive...
|
245 |
my $append = $args{append}; |
select, insert, update, upda...
|
246 |
my $filter = $args{filter}; |
cleanup
|
247 |
my $allow_delete_all = $args{allow_delete_all}; |
added auto_filter method
|
248 | |
make delete() using where ob...
|
249 |
# Where |
250 |
my $w; |
|
251 |
if (ref $where eq 'HASH') { |
|
252 |
my $clause = ['and']; |
|
253 |
push @$clause, "{= $_}" for keys %$where; |
|
254 |
$w = $self->where; |
|
255 |
$w->clause($clause); |
|
improved delete() and update...
|
256 |
$w->param($where); |
packaging one directory
|
257 |
} |
select() where can't receive...
|
258 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
259 |
$w = $where; |
|
260 |
$where = $w->param; |
|
261 |
} |
|
make delete() using where ob...
|
262 |
croak qq{"where" must be hash refernce or DBIx::Custom::Where object} |
263 |
unless ref $w eq 'DBIx::Custom::Where'; |
|
264 |
|
|
select() where can't receive...
|
265 |
# String where |
266 |
my $swhere = "$w"; |
|
improved delete() and update...
|
267 |
|
make delete() using where ob...
|
268 |
croak qq{"where" must be specified} |
select() where can't receive...
|
269 |
if $swhere eq '' && !$allow_delete_all; |
make delete() using where ob...
|
270 | |
cleanup
|
271 |
# SQL stack |
272 |
my @sql; |
|
273 | ||
274 |
# Delete |
|
275 |
push @sql, "delete from $table $swhere"; |
|
276 |
push @sql, $append if $append; |
|
277 |
|
|
278 |
my $sql = join(' ', @sql); |
|
packaging one directory
|
279 |
|
added experimental sugar met...
|
280 |
# Create query |
cleanup
|
281 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
282 |
return $query if $args{query}; |
283 |
|
|
packaging one directory
|
284 |
# Execute query |
added auto_filter method
|
285 |
my $ret_val = $self->execute( |
added experimental sugar met...
|
286 |
$query, param => $where, filter => $filter, |
renamed auto_filter to apply...
|
287 |
table => $table); |
packaging one directory
|
288 |
|
289 |
return $ret_val; |
|
290 |
} |
|
291 | ||
cleanup
|
292 |
sub delete_all { shift->delete(allow_delete_all => 1, @_) } |
packaging one directory
|
293 | |
add experimental update_at()...
|
294 |
our %VALID_DELETE_AT_ARGS |
295 |
= map { $_ => 1 } qw/table where append filter query |
|
296 |
primary_key param/; |
|
297 | ||
298 |
sub delete_at { |
|
299 |
my ($self, %args) = @_; |
|
300 |
|
|
301 |
# Check arguments |
|
302 |
foreach my $name (keys %args) { |
|
303 |
croak qq{"$name" is invalid argument} |
|
304 |
unless $VALID_DELETE_AT_ARGS{$name}; |
|
305 |
} |
|
306 |
|
|
307 |
# Primary key |
|
308 |
my $primary_keys = delete $args{primary_key}; |
|
309 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
310 |
|
|
311 |
# Where clause |
|
312 |
my $where = {}; |
|
313 |
if (exists $args{where}) { |
|
314 |
my $where_columns = delete $args{where}; |
|
315 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
316 |
|
|
317 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
318 |
$where->{$primary_keys->[$i]} = $where_columns->[$i]; |
|
319 |
} |
|
320 |
} |
|
321 |
elsif (exists $args{param}) { |
|
322 |
my $param = delete $args{param}; |
|
323 |
|
|
324 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
325 |
$where->{$primary_keys->[$i]} |
|
326 |
= delete $param->{$primary_keys->[$i]}; |
|
327 |
} |
|
328 |
} |
|
329 |
|
|
330 |
return $self->delete(where => $where, %args); |
|
331 |
} |
|
332 | ||
added helper method
|
333 |
sub DESTROY { } |
334 | ||
renamed auto_filter to apply...
|
335 |
our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter table/; |
refactoring delete and delet...
|
336 | |
cleanup
|
337 |
sub execute{ |
338 |
my ($self, $query, %args) = @_; |
|
refactoring delete and delet...
|
339 |
|
340 |
# Check arguments |
|
select, insert, update, upda...
|
341 |
foreach my $name (keys %args) { |
add tests
|
342 |
croak qq{"$name" is invalid argument} |
cleanup
|
343 |
unless $VALID_EXECUTE_ARGS{$name}; |
refactoring delete and delet...
|
344 |
} |
345 |
|
|
cleanup
|
346 |
my $params = $args{param} || {}; |
packaging one directory
|
347 |
|
cleanup
|
348 |
# First argument is the soruce of SQL |
349 |
$query = $self->create_query($query) |
|
350 |
unless ref $query; |
|
packaging one directory
|
351 |
|
add table tag
|
352 |
# Applied filter |
cleanup
|
353 |
my $filter = {}; |
add table tag
|
354 |
my $tables = $query->tables; |
355 |
my $arg_tables = $args{table} || []; |
|
356 |
$arg_tables = [$arg_tables] |
|
357 |
unless ref $arg_tables eq 'ARRAY'; |
|
358 |
push @$tables, @$arg_tables; |
|
renamed auto_filter to apply...
|
359 |
foreach my $table (@$tables) { |
cleanup
|
360 |
$filter = { |
361 |
%$filter, |
|
362 |
%{$self->{filter}{out}->{$table} || {}} |
|
added auto_filter method
|
363 |
} |
364 |
} |
|
365 |
|
|
cleanup
|
366 |
# Filter argument |
367 |
my $f = $args{filter} || $query->filter || {}; |
|
368 |
foreach my $column (keys %$f) { |
|
369 |
my $fname = $f->{$column}; |
|
renamed auto_filter to apply...
|
370 |
if (!defined $fname) { |
cleanup
|
371 |
$f->{$column} = undef; |
renamed auto_filter to apply...
|
372 |
} |
373 |
elsif (ref $fname ne 'CODE') { |
|
many changed
|
374 |
croak qq{Filter "$fname" is not registered"} |
cleanup
|
375 |
unless exists $self->filters->{$fname}; |
376 |
|
|
cleanup
|
377 |
$f->{$column} = $self->filters->{$fname}; |
cleanup
|
378 |
} |
379 |
} |
|
cleanup
|
380 |
$filter = {%$filter, %$f}; |
packaging one directory
|
381 |
|
added experimental not_exist...
|
382 |
# Bind |
383 |
my $bind = $self->_bind($params, $query->columns, $filter); |
|
cleanup
|
384 |
|
385 |
# Execute |
|
added experimental not_exist...
|
386 |
my $sth = $query->sth; |
cleanup
|
387 |
my $affected; |
added experimental not_exist...
|
388 |
eval {$affected = $sth->execute(@$bind)}; |
renamed DBIx::Custom::TagPro...
|
389 |
$self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@; |
cleanup
|
390 |
|
391 |
# Return resultset if select statement is executed |
|
392 |
if ($sth->{NUM_OF_FIELDS}) { |
|
393 |
|
|
fix bug : filter can't over...
|
394 |
# Result in and end filter |
395 |
my $in_filter = {}; |
|
396 |
my $end_filter = {}; |
|
cleanup
|
397 |
foreach my $table (@$tables) { |
398 |
$in_filter = { |
|
399 |
%$in_filter, |
|
400 |
%{$self->{filter}{in}{$table} || {}} |
|
fix bug : filter can't over...
|
401 |
}; |
402 |
$end_filter = { |
|
403 |
%$end_filter, |
|
404 |
%{$self->{filter}{end}{$table} || {}} |
|
405 |
}; |
|
cleanup
|
406 |
} |
407 |
|
|
408 |
# Result |
|
409 |
my $result = $self->result_class->new( |
|
cleanup
|
410 |
sth => $sth, |
411 |
filters => $self->filters, |
|
412 |
filter_check => $self->filter_check, |
|
cleanup
|
413 |
default_filter => $self->{default_in_filter}, |
fix bug : filter can't over...
|
414 |
filter => $in_filter || {}, |
415 |
end_filter => $end_filter || {} |
|
cleanup
|
416 |
); |
417 | ||
418 |
return $result; |
|
419 |
} |
|
420 |
return $affected; |
|
421 |
} |
|
422 | ||
added auto_filter method
|
423 |
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append |
added experimental sugar met...
|
424 |
filter query/; |
cleanup
|
425 |
sub insert { |
426 |
my ($self, %args) = @_; |
|
427 | ||
428 |
# Check arguments |
|
429 |
foreach my $name (keys %args) { |
|
430 |
croak qq{"$name" is invalid argument} |
|
431 |
unless $VALID_INSERT_ARGS{$name}; |
|
packaging one directory
|
432 |
} |
433 |
|
|
cleanup
|
434 |
# Arguments |
added table not specified ex...
|
435 |
my $table = $args{table}; |
436 |
croak qq{"table" option must be specified} unless $table; |
|
cleanup
|
437 |
my $param = $args{param} || {}; |
438 |
my $append = $args{append} || ''; |
|
439 |
my $filter = $args{filter}; |
|
440 |
|
|
select() where can't receive...
|
441 |
# Columns |
442 |
my @columns; |
|
443 |
my $safety = $self->safety_column_name; |
|
444 |
foreach my $column (keys %$param) { |
|
445 |
croak qq{"$column" is not safety column name} |
|
446 |
unless $column =~ /$safety/; |
|
447 |
push @columns, $column; |
|
448 |
} |
|
cleanup
|
449 |
|
cleanup
|
450 |
# SQL stack |
451 |
my @sql; |
|
452 |
|
|
453 |
# Insert |
|
454 |
push @sql, "insert into $table {insert_param ". join(' ', @columns) . '}'; |
|
455 |
push @sql, $append if $append; |
|
456 |
|
|
select() where can't receive...
|
457 |
# SQL |
cleanup
|
458 |
my $sql = join (' ', @sql); |
packaging one directory
|
459 |
|
added experimental sugar met...
|
460 |
# Create query |
cleanup
|
461 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
462 |
return $query if $args{query}; |
463 |
|
|
packaging one directory
|
464 |
# Execute query |
added auto_filter method
|
465 |
my $ret_val = $self->execute( |
added experimental sugar met...
|
466 |
$query, |
added auto_filter method
|
467 |
param => $param, |
468 |
filter => $filter, |
|
renamed auto_filter to apply...
|
469 |
table => $table |
added auto_filter method
|
470 |
); |
packaging one directory
|
471 |
|
472 |
return $ret_val; |
|
473 |
} |
|
474 | ||
pod fix
|
475 |
sub each_column { |
added experimental iterate_a...
|
476 |
my ($self, $cb) = @_; |
477 |
|
|
478 |
# Iterate all tables |
|
479 |
my $sth_tables = $self->dbh->table_info; |
|
480 |
while (my $table_info = $sth_tables->fetchrow_hashref) { |
|
481 |
|
|
482 |
# Table |
|
483 |
my $table = $table_info->{TABLE_NAME}; |
|
484 |
|
|
485 |
# Iterate all columns |
|
486 |
my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%'); |
|
487 |
while (my $column_info = $sth_columns->fetchrow_hashref) { |
|
488 |
my $column = $column_info->{COLUMN_NAME}; |
|
removed experimental txn_sco...
|
489 |
$self->$cb($table, $column, $column_info); |
added experimental iterate_a...
|
490 |
} |
491 |
} |
|
492 |
} |
|
493 | ||
added dbi_options attribute
|
494 |
sub new { |
495 |
my $self = shift->SUPER::new(@_); |
|
496 |
|
|
497 |
# Check attribute names |
|
498 |
my @attrs = keys %$self; |
|
499 |
foreach my $attr (@attrs) { |
|
500 |
croak qq{"$attr" is invalid attribute name} |
|
501 |
unless $self->can($attr); |
|
502 |
} |
|
cleanup
|
503 | |
504 |
$self->register_tag( |
|
505 |
'?' => \&DBIx::Custom::Tag::placeholder, |
|
506 |
'=' => \&DBIx::Custom::Tag::equal, |
|
507 |
'<>' => \&DBIx::Custom::Tag::not_equal, |
|
508 |
'>' => \&DBIx::Custom::Tag::greater_than, |
|
509 |
'<' => \&DBIx::Custom::Tag::lower_than, |
|
510 |
'>=' => \&DBIx::Custom::Tag::greater_than_equal, |
|
511 |
'<=' => \&DBIx::Custom::Tag::lower_than_equal, |
|
512 |
'like' => \&DBIx::Custom::Tag::like, |
|
513 |
'in' => \&DBIx::Custom::Tag::in, |
|
514 |
'insert_param' => \&DBIx::Custom::Tag::insert_param, |
|
515 |
'update_param' => \&DBIx::Custom::Tag::update_param |
|
516 |
); |
|
added dbi_options attribute
|
517 |
|
518 |
return $self; |
|
519 |
} |
|
520 | ||
added experimental not_exist...
|
521 |
sub not_exists { bless {}, 'DBIx::Custom::NotExists' } |
522 | ||
cleanup
|
523 |
sub register_filter { |
524 |
my $invocant = shift; |
|
525 |
|
|
526 |
# Register filter |
|
527 |
my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
528 |
$invocant->filters({%{$invocant->filters}, %$filters}); |
|
529 |
|
|
530 |
return $invocant; |
|
531 |
} |
|
packaging one directory
|
532 | |
renamed DBIx::Custom::TagPro...
|
533 |
sub register_tag { shift->query_builder->register_tag(@_) } |
added register_tag_processor
|
534 | |
refactoring select
|
535 |
our %VALID_SELECT_ARGS |
add experimental selection o...
|
536 |
= map { $_ => 1 } qw/table column where append relation filter query selection/; |
refactoring select
|
537 | |
packaging one directory
|
538 |
sub select { |
select, insert, update, upda...
|
539 |
my ($self, %args) = @_; |
packaging one directory
|
540 |
|
refactoring select
|
541 |
# Check arguments |
select, insert, update, upda...
|
542 |
foreach my $name (keys %args) { |
add tests
|
543 |
croak qq{"$name" is invalid argument} |
refactoring select
|
544 |
unless $VALID_SELECT_ARGS{$name}; |
545 |
} |
|
packaging one directory
|
546 |
|
refactoring select
|
547 |
# Arguments |
added table not specified ex...
|
548 |
my $table = $args{table}; |
549 |
my $tables = ref $table eq 'ARRAY' ? $table |
|
550 |
: defined $table ? [$table] |
|
551 |
: []; |
|
add experimental selection o...
|
552 |
my $columns = $args{column} || []; |
553 |
my $selection = $args{selection} || ''; |
|
554 |
my $where = $args{where} || {}; |
|
DBIx::Custom::Model select()...
|
555 |
my $relation = $args{relation} || {}; |
add experimental selection o...
|
556 |
my $append = $args{append}; |
557 |
my $filter = $args{filter}; |
|
add experimental DBIx::Custo...
|
558 | |
DBIx::Custom::Model select()...
|
559 |
# Relation |
560 |
if (!$selection && keys %$relation) { |
|
add experimental DBIx::Custo...
|
561 |
foreach my $rcolumn (keys %$relation) { |
562 |
my $table1 = (split (/\./, $rcolumn))[0]; |
|
563 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
564 |
|
|
565 |
my $table1_exists; |
|
566 |
my $table2_exists; |
|
567 |
foreach my $table (@$tables) { |
|
568 |
$table1_exists = 1 if $table eq $table1; |
|
569 |
$table2_exists = 1 if $table eq $table2; |
|
570 |
} |
|
DBIx::Custom::Model select()...
|
571 |
unshift @$tables, $table1 unless $table1_exists; |
572 |
unshift @$tables, $table2 unless $table2_exists; |
|
add experimental DBIx::Custo...
|
573 |
} |
574 |
} |
|
packaging one directory
|
575 |
|
cleanup
|
576 |
# SQL stack |
577 |
my @sql; |
|
578 |
|
|
579 |
push @sql, 'select'; |
|
packaging one directory
|
580 |
|
add experimental selection o...
|
581 |
if ($selection) { |
582 |
croak qq{Can't contain "where" clause in selection} |
|
583 |
if $selection =~ /\swhere\s/; |
|
584 |
push @sql, $selection; |
|
585 |
} |
|
586 |
else { |
|
587 |
# Column clause |
|
588 |
if (@$columns) { |
|
589 |
foreach my $column (@$columns) { |
|
590 |
push @sql, ($column, ','); |
|
591 |
} |
|
592 |
pop @sql if $sql[-1] eq ','; |
|
593 |
} |
|
594 |
else { push @sql, '*' } |
|
595 |
|
|
596 |
# Table |
|
597 |
croak qq{"table" option must be specified} unless @$tables; |
|
598 |
push @sql, 'from'; |
|
599 |
foreach my $table (@$tables) { |
|
600 |
push @sql, ($table, ','); |
|
packaging one directory
|
601 |
} |
cleanup
|
602 |
pop @sql if $sql[-1] eq ','; |
packaging one directory
|
603 |
} |
604 |
|
|
select() where can't receive...
|
605 |
# Where |
606 |
my $w; |
|
added experimental DBIx::Cus...
|
607 |
if (ref $where eq 'HASH') { |
select() where can't receive...
|
608 |
my $clause = ['and']; |
609 |
push @$clause, "{= $_}" for keys %$where; |
|
610 |
$w = $self->where; |
|
611 |
$w->clause($clause); |
|
612 |
$w->param($where); |
|
added experimental DBIx::Cus...
|
613 |
} |
614 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
|
select() where can't receive...
|
615 |
$w = $where; |
616 |
$where = $w->param; |
|
packaging one directory
|
617 |
} |
618 |
|
|
select() where can't receive...
|
619 |
croak qq{"where" must be hash reference or DBIx::Custom::Where object} |
620 |
unless ref $w eq 'DBIx::Custom::Where'; |
|
621 |
|
|
622 |
# String where |
|
623 |
my $swhere = "$w"; |
|
cleanup
|
624 |
push @sql, $swhere; |
select() where can't receive...
|
625 |
|
added commit method
|
626 |
# Relation |
DBIx::Custom::Model select()...
|
627 |
if (!$selection && keys %$relation) { |
cleanup
|
628 |
push @sql, $swhere eq '' ? 'where' : 'and'; |
629 |
foreach my $rcolumn (keys %$relation) { |
|
add experimental DBIx::Custo...
|
630 |
my $table1 = (split (/\./, $rcolumn))[0]; |
631 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
632 |
push @$tables, ($table1, $table2); |
|
633 |
|
|
cleanup
|
634 |
push @sql, ("$rcolumn = " . $relation->{$rcolumn}, 'and'); |
packaging one directory
|
635 |
} |
636 |
} |
|
cleanup
|
637 |
pop @sql if $sql[-1] eq 'and'; |
added commit method
|
638 |
|
cleanup
|
639 |
# Append statement |
640 |
push @sql, $append if $append; |
|
641 |
|
|
642 |
# SQL |
|
643 |
my $sql = join (' ', @sql); |
|
packaging one directory
|
644 |
|
added experimental sugar met...
|
645 |
# Create query |
cleanup
|
646 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
647 |
return $query if $args{query}; |
648 |
|
|
packaging one directory
|
649 |
# Execute query |
added auto_filter method
|
650 |
my $result = $self->execute( |
select() where can't receive...
|
651 |
$query, param => $where, filter => $filter, |
652 |
table => $tables); |
|
packaging one directory
|
653 |
|
654 |
return $result; |
|
655 |
} |
|
656 | ||
add experimental update_at()...
|
657 |
our %VALID_SELECT_AT_ARGS |
658 |
= map { $_ => 1 } qw/table column where append relation filter query selection |
|
659 |
param primary_key/; |
|
660 | ||
661 |
sub select_at { |
|
662 |
my ($self, %args) = @_; |
|
663 |
|
|
664 |
# Check arguments |
|
665 |
foreach my $name (keys %args) { |
|
666 |
croak qq{"$name" is invalid argument} |
|
667 |
unless $VALID_SELECT_AT_ARGS{$name}; |
|
668 |
} |
|
669 |
|
|
670 |
# Primary key |
|
671 |
my $primary_keys = delete $args{primary_key}; |
|
672 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
673 |
|
|
DBIx::Custom::Model select()...
|
674 |
# Table |
675 |
croak qq{"table" option must be specified} unless $args{table}; |
|
676 |
my $table = ref $args{table} ? $args{table}->[-1] : $args{table}; |
|
677 |
|
|
add experimental update_at()...
|
678 |
# Where clause |
679 |
my $where = {}; |
|
680 |
if (exists $args{where}) { |
|
681 |
my $where_columns = delete $args{where}; |
|
682 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
683 |
|
|
684 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
DBIx::Custom::Model select()...
|
685 |
$where->{$table . '.' . $primary_keys->[$i]} = $where_columns->[$i]; |
add experimental update_at()...
|
686 |
} |
687 |
} |
|
688 |
elsif (exists $args{param}) { |
|
689 |
my $param = delete $args{param}; |
|
690 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
691 |
$where->{$primary_keys->[$i]} |
|
692 |
= delete $param->{$primary_keys->[$i]}; |
|
693 |
} |
|
694 |
} |
|
695 |
|
|
696 |
return $self->select(where => $where, %args); |
|
697 |
} |
|
698 | ||
add feture. all model class ...
|
699 |
sub model { |
700 |
my ($self, $name, $model) = @_; |
|
removed experimental base_ta...
|
701 |
|
702 |
# Set |
|
add feture. all model class ...
|
703 |
if ($model) { |
add models() attribute
|
704 |
$self->models->{$name} = $model; |
removed experimental base_ta...
|
705 |
return $self; |
706 |
} |
|
707 |
|
|
add feture. all model class ...
|
708 |
# Check model existance |
709 |
croak qq{Model "$name" is not included} |
|
add models() attribute
|
710 |
unless $self->models->{$name}; |
removed experimental base_ta...
|
711 |
|
712 |
# Get |
|
add models() attribute
|
713 |
return $self->models->{$name}; |
removed experimental base_ta...
|
714 |
} |
715 | ||
add feture. all model class ...
|
716 |
sub include_model { |
717 |
my ($self, $name_space, $model_infos) = @_; |
|
remove DBIx::Custom::Model
|
718 |
|
add feture. all model class ...
|
719 |
$name_space ||= ''; |
720 |
unless ($model_infos) { |
|
721 |
# Load name space module |
|
722 |
croak qq{"$name_space" is invalid class name} |
|
723 |
if $name_space =~ /[^\w:]/; |
|
724 |
eval "use $name_space"; |
|
725 |
croak qq{Name space module "$name_space.pm" is needed. $@} if $@; |
|
table object call dbi object...
|
726 |
|
add feture. all model class ...
|
727 |
# Search model modules |
728 |
my $path = $INC{"$name_space.pm"}; |
|
729 |
$path =~ s/\.pm$//; |
|
730 |
opendir my $dh, $path |
|
731 |
or croak qq{Can't open directory "$path": $!}; |
|
732 |
$model_infos = []; |
|
733 |
while (my $module = readdir $dh) { |
|
734 |
push @$model_infos, $module |
|
735 |
if $module =~ s/\.pm$//; |
|
removed experimental base_ta...
|
736 |
} |
add feture. all model class ...
|
737 |
|
738 |
close $dh; |
|
739 |
} |
|
740 |
|
|
741 |
foreach my $model_info (@$model_infos) { |
|
742 |
|
|
743 |
# Model name and class |
|
744 |
my $model_name; |
|
745 |
my $model_class; |
|
746 |
if (ref $model_info eq 'HASH') { |
|
747 |
$model_name = (keys %$model_info)[0]; |
|
748 |
$model_class = $model_info->{$model_name}; |
|
749 |
} |
|
750 |
else { $model_name = $model_class = $model_info } |
|
751 |
my $mclass = "${name_space}::$model_class"; |
|
table object call dbi object...
|
752 |
|
removed experimental base_ta...
|
753 |
# Load |
add feture. all model class ...
|
754 |
croak qq{"$mclass" is invalid class name} |
755 |
if $mclass =~ /[^\w:]/; |
|
756 |
unless ($mclass->can('isa')) { |
|
757 |
eval "use $mclass"; |
|
removed experimental base_ta...
|
758 |
croak $@ if $@; |
759 |
} |
|
table object call dbi object...
|
760 |
|
removed experimental base_ta...
|
761 |
# Instantiate |
add feture. all model class ...
|
762 |
my $model = $mclass->new(dbi => $self); |
763 |
$model->table($model_name) unless $model->table; |
|
removed experimental DBIx::C...
|
764 |
|
removed experimental base_ta...
|
765 |
# Set |
add feture. all model class ...
|
766 |
$self->model($model_name, $model); |
table object call dbi object...
|
767 |
} |
removed experimental base_ta...
|
768 |
return $self; |
remove DBIx::Custom::Model
|
769 |
} |
770 | ||
add experimental setup_model...
|
771 |
sub setup_model { |
772 |
my $self = shift; |
|
773 |
|
|
774 |
$self->each_column( |
|
775 |
sub { |
|
776 |
my ($self, $table, $column, $column_info) = @_; |
|
777 |
|
|
778 |
if (my $model = $self->models->{$table}) { |
|
779 |
push @{$model->columns}, $column; |
|
780 |
} |
|
781 |
} |
|
782 |
); |
|
783 |
} |
|
784 | ||
cleanup
|
785 |
our %VALID_UPDATE_ARGS |
renamed auto_filter to apply...
|
786 |
= map { $_ => 1 } qw/table param |
added experimental sugar met...
|
787 |
where append filter allow_update_all query/; |
cleanup
|
788 | |
789 |
sub update { |
|
790 |
my ($self, %args) = @_; |
|
version 0.0901
|
791 |
|
cleanup
|
792 |
# Check arguments |
793 |
foreach my $name (keys %args) { |
|
794 |
croak qq{"$name" is invalid argument} |
|
795 |
unless $VALID_UPDATE_ARGS{$name}; |
|
removed reconnect method
|
796 |
} |
added cache_method attribute
|
797 |
|
cleanup
|
798 |
# Arguments |
799 |
my $table = $args{table} || ''; |
|
added table not specified ex...
|
800 |
croak qq{"table" option must be specified} unless $table; |
cleanup
|
801 |
my $param = $args{param} || {}; |
802 |
my $where = $args{where} || {}; |
|
select() where can't receive...
|
803 |
my $append = $args{append} || ''; |
cleanup
|
804 |
my $filter = $args{filter}; |
805 |
my $allow_update_all = $args{allow_update_all}; |
|
version 0.0901
|
806 |
|
cleanup
|
807 |
# Update keys |
select() where can't receive...
|
808 |
my @clumns = keys %$param; |
809 | ||
810 |
# Columns |
|
811 |
my @columns; |
|
812 |
my $safety = $self->safety_column_name; |
|
813 |
foreach my $column (keys %$param) { |
|
814 |
croak qq{"$column" is not safety column name} |
|
815 |
unless $column =~ /$safety/; |
|
816 |
push @columns, $column; |
|
817 |
} |
|
818 |
|
|
cleanup
|
819 |
# Update clause |
select() where can't receive...
|
820 |
my $update_clause = '{update_param ' . join(' ', @clumns) . '}'; |
improved delete() and update...
|
821 | |
822 |
# Where |
|
823 |
my $w; |
|
824 |
if (ref $where eq 'HASH') { |
|
825 |
my $clause = ['and']; |
|
826 |
push @$clause, "{= $_}" for keys %$where; |
|
827 |
$w = $self->where; |
|
828 |
$w->clause($clause); |
|
829 |
$w->param($where); |
|
830 |
} |
|
select() where can't receive...
|
831 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
832 |
$w = $where; |
|
833 |
$where = $w->param; |
|
834 |
} |
|
removed experimental registe...
|
835 |
|
improved delete() and update...
|
836 |
croak qq{"where" must be hash refernce or DBIx::Custom::Where object} |
837 |
unless ref $w eq 'DBIx::Custom::Where'; |
|
removed reconnect method
|
838 |
|
select() where can't receive...
|
839 |
# String where |
840 |
my $swhere = "$w"; |
|
improved delete() and update...
|
841 |
|
842 |
croak qq{"where" must be specified} |
|
select() where can't receive...
|
843 |
if "$swhere" eq '' && !$allow_update_all; |
removed reconnect method
|
844 |
|
cleanup
|
845 |
# SQL stack |
846 |
my @sql; |
|
847 |
|
|
848 |
# Update |
|
849 |
push @sql, "update $table $update_clause $swhere"; |
|
850 |
push @sql, $append if $append; |
|
removed reconnect method
|
851 |
|
cleanup
|
852 |
# Rearrange parameters |
improved delete() and update...
|
853 |
foreach my $wkey (keys %$where) { |
removed reconnect method
|
854 |
|
cleanup
|
855 |
if (exists $param->{$wkey}) { |
856 |
$param->{$wkey} = [$param->{$wkey}] |
|
857 |
unless ref $param->{$wkey} eq 'ARRAY'; |
|
858 |
|
|
859 |
push @{$param->{$wkey}}, $where->{$wkey}; |
|
860 |
} |
|
861 |
else { |
|
862 |
$param->{$wkey} = $where->{$wkey}; |
|
863 |
} |
|
removed reconnect method
|
864 |
} |
cleanup
|
865 |
|
cleanup
|
866 |
# SQL |
867 |
my $sql = join(' ', @sql); |
|
868 |
|
|
added experimental sugar met...
|
869 |
# Create query |
cleanup
|
870 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
871 |
return $query if $args{query}; |
872 |
|
|
cleanup
|
873 |
# Execute query |
added experimental sugar met...
|
874 |
my $ret_val = $self->execute($query, param => $param, |
added auto_filter method
|
875 |
filter => $filter, |
renamed auto_filter to apply...
|
876 |
table => $table); |
cleanup
|
877 |
|
878 |
return $ret_val; |
|
removed reconnect method
|
879 |
} |
880 | ||
cleanup
|
881 |
sub update_all { shift->update(allow_update_all => 1, @_) }; |
882 | ||
add experimental update_at()...
|
883 |
our %VALID_UPDATE_AT_ARGS |
884 |
= map { $_ => 1 } qw/table param |
|
885 |
where append filter query |
|
886 |
primary_key param/; |
|
887 | ||
888 |
sub update_at { |
|
889 |
my ($self, %args) = @_; |
|
890 |
|
|
891 |
# Check arguments |
|
892 |
foreach my $name (keys %args) { |
|
893 |
croak qq{"$name" is invalid argument} |
|
894 |
unless $VALID_UPDATE_AT_ARGS{$name}; |
|
895 |
} |
|
896 |
|
|
897 |
# Primary key |
|
898 |
my $primary_keys = delete $args{primary_key}; |
|
899 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
900 |
|
|
901 |
# Where clause |
|
902 |
my $where = {}; |
|
903 |
my $param = {}; |
|
904 |
|
|
905 |
if (exists $args{where}) { |
|
906 |
my $where_columns = delete $args{where}; |
|
907 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
908 |
|
|
909 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
910 |
$where->{$primary_keys->[$i]} = $where_columns->[$i]; |
|
911 |
} |
|
912 |
} |
|
913 |
elsif (exists $args{param}) { |
|
914 |
$param = delete $args{param}; |
|
915 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
916 |
$where->{$primary_keys->[$i]} |
|
917 |
= delete $param->{$primary_keys->[$i]}; |
|
918 |
} |
|
919 |
} |
|
920 |
|
|
921 |
return $self->update(where => $where, param => $param, %args); |
|
922 |
} |
|
923 | ||
cleanup
|
924 |
sub where { |
select() where can't receive...
|
925 |
my $self = shift; |
926 | ||
927 |
return DBIx::Custom::Where->new( |
|
928 |
query_builder => $self->query_builder, |
|
929 |
safety_column_name => $self->safety_column_name |
|
930 |
); |
|
cleanup
|
931 |
} |
added experimental DBIx::Cus...
|
932 | |
added experimental not_exist...
|
933 |
sub _bind { |
cleanup
|
934 |
my ($self, $params, $columns, $filter) = @_; |
removed reconnect method
|
935 |
|
cleanup
|
936 |
# bind values |
added experimental not_exist...
|
937 |
my @bind; |
add tests
|
938 |
|
removed reconnect method
|
939 |
# Build bind values |
940 |
my $count = {}; |
|
added experimental not_exist...
|
941 |
my $not_exists = {}; |
cleanup
|
942 |
foreach my $column (@$columns) { |
removed reconnect method
|
943 |
|
944 |
# Value |
|
added experimental not_exist...
|
945 |
my $value; |
946 |
if(ref $params->{$column} eq 'ARRAY') { |
|
947 |
my $i = $count->{$column} || 0; |
|
948 |
$i += $not_exists->{$column} || 0; |
|
949 |
my $found; |
|
950 |
for (my $k = $i; $i < @{$params->{$column}}; $k++) { |
|
951 |
if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') { |
|
952 |
$not_exists->{$column}++; |
|
953 |
} |
|
954 |
else { |
|
955 |
$value = $params->{$column}->[$k]; |
|
956 |
$found = 1; |
|
957 |
last |
|
958 |
} |
|
959 |
} |
|
960 |
next unless $found; |
|
961 |
} |
|
962 |
else { $value = $params->{$column} } |
|
removed reconnect method
|
963 |
|
cleanup
|
964 |
# Filter |
965 |
my $f = $filter->{$column} || $self->{default_out_filter} || ''; |
|
cleanup
|
966 |
|
added experimental not_exist...
|
967 |
push @bind, $f ? $f->($value) : $value; |
removed reconnect method
|
968 |
|
969 |
# Count up |
|
970 |
$count->{$column}++; |
|
971 |
} |
|
972 |
|
|
added experimental not_exist...
|
973 |
return \@bind; |
removed reconnect method
|
974 |
} |
975 | ||
cleanup
|
976 |
sub _croak { |
977 |
my ($self, $error, $append) = @_; |
|
978 |
$append ||= ""; |
|
979 |
|
|
980 |
# Verbose |
|
981 |
if ($Carp::Verbose) { croak $error } |
|
982 |
|
|
983 |
# Not verbose |
|
984 |
else { |
|
985 |
|
|
986 |
# Remove line and module infromation |
|
987 |
my $at_pos = rindex($error, ' at '); |
|
988 |
$error = substr($error, 0, $at_pos); |
|
989 |
$error =~ s/\s+$//; |
|
990 |
|
|
991 |
croak "$error$append"; |
|
992 |
} |
|
993 |
} |
|
994 | ||
cleanup
|
995 |
# DEPRECATED! |
cleanup
|
996 |
__PACKAGE__->attr( |
997 |
dbi_options => sub { {} }, |
|
998 |
filter_check => 1 |
|
999 |
); |
|
renamed dbi_options to dbi_o...
|
1000 | |
cleanup
|
1001 |
# DEPRECATED! |
cleanup
|
1002 |
sub default_bind_filter { |
1003 |
my $self = shift; |
|
1004 |
|
|
1005 |
if (@_) { |
|
1006 |
my $fname = $_[0]; |
|
1007 |
|
|
1008 |
if (@_ && !$fname) { |
|
1009 |
$self->{default_out_filter} = undef; |
|
1010 |
} |
|
1011 |
else { |
|
many changed
|
1012 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
1013 |
unless exists $self->filters->{$fname}; |
1014 |
|
|
1015 |
$self->{default_out_filter} = $self->filters->{$fname}; |
|
1016 |
} |
|
1017 |
return $self; |
|
1018 |
} |
|
1019 |
|
|
1020 |
return $self->{default_out_filter}; |
|
1021 |
} |
|
1022 | ||
cleanup
|
1023 |
# DEPRECATED! |
cleanup
|
1024 |
sub default_fetch_filter { |
1025 |
my $self = shift; |
|
1026 |
|
|
1027 |
if (@_) { |
|
many changed
|
1028 |
my $fname = $_[0]; |
1029 | ||
cleanup
|
1030 |
if (@_ && !$fname) { |
1031 |
$self->{default_in_filter} = undef; |
|
1032 |
} |
|
1033 |
else { |
|
many changed
|
1034 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
1035 |
unless exists $self->filters->{$fname}; |
1036 |
|
|
1037 |
$self->{default_in_filter} = $self->filters->{$fname}; |
|
1038 |
} |
|
1039 |
|
|
1040 |
return $self; |
|
1041 |
} |
|
1042 |
|
|
many changed
|
1043 |
return $self->{default_in_filter}; |
cleanup
|
1044 |
} |
1045 | ||
cleanup
|
1046 |
# DEPRECATED! |
renamed DBIx::Custom::TagPro...
|
1047 |
sub register_tag_processor { |
1048 |
return shift->query_builder->register_tag_processor(@_); |
|
1049 |
} |
|
1050 | ||
fixed DBIx::Custom::QueryBui...
|
1051 |
1; |
1052 | ||
removed reconnect method
|
1053 |
=head1 NAME |
1054 | ||
renamed build_query to creat...
|
1055 |
DBIx::Custom - DBI interface, having hash parameter binding and filtering system |
removed reconnect method
|
1056 | |
1057 |
=head1 SYNOPSYS |
|
cleanup
|
1058 | |
renamed build_query to creat...
|
1059 |
use DBIx::Custom; |
renamed update tag to update...
|
1060 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
renamed dbi_options to dbi_o...
|
1061 |
user => 'ken', password => '!LFKD%$&', |
1062 |
dbi_option => {mysql_enable_utf8 => 1}); |
|
cleanup
|
1063 | |
removed reconnect method
|
1064 |
# Insert |
added insert, update, update...
|
1065 |
$dbi->insert(table => 'book', |
renamed update tag to update...
|
1066 |
param => {title => 'Perl', author => 'Ken'}, |
renamed dbi_options to dbi_o...
|
1067 |
filter => {title => 'to_something'}); |
removed reconnect method
|
1068 |
|
1069 |
# Update |
|
added insert, update, update...
|
1070 |
$dbi->update(table => 'book', |
renamed update tag to update...
|
1071 |
param => {title => 'Perl', author => 'Ken'}, |
removed reconnect method
|
1072 |
where => {id => 5}, |
renamed dbi_options to dbi_o...
|
1073 |
filter => {title => 'to_something'}); |
removed reconnect method
|
1074 |
|
1075 |
# Update all |
|
added insert, update, update...
|
1076 |
$dbi->update_all(table => 'book', |
renamed update tag to update...
|
1077 |
param => {title => 'Perl'}, |
renamed dbi_options to dbi_o...
|
1078 |
filter => {title => 'to_something'}); |
removed reconnect method
|
1079 |
|
1080 |
# Delete |
|
added insert, update, update...
|
1081 |
$dbi->delete(table => 'book', |
removed reconnect method
|
1082 |
where => {author => 'Ken'}, |
renamed dbi_options to dbi_o...
|
1083 |
filter => {title => 'to_something'}); |
removed reconnect method
|
1084 |
|
1085 |
# Delete all |
|
added insert, update, update...
|
1086 |
$dbi->delete_all(table => 'book'); |
cleanup
|
1087 | |
removed reconnect method
|
1088 |
# Select |
renamed fetch_rows to fetch_...
|
1089 |
my $result = $dbi->select( |
added insert, update, update...
|
1090 |
table => 'book', |
update document
|
1091 |
column => [qw/author title/], |
1092 |
where => {author => 'Ken'}, |
|
renamed dbi_options to dbi_o...
|
1093 |
relation => {'book.id' => 'rental.book_id'}, |
updated document
|
1094 |
append => 'order by id limit 5', |
renamed dbi_options to dbi_o...
|
1095 |
filter => {title => 'to_something'} |
added commit method
|
1096 |
); |
cleanup
|
1097 | |
renamed build_query to creat...
|
1098 |
# Execute SQL |
added insert, update, update...
|
1099 |
$dbi->execute("select title from book"); |
removed register_format()
|
1100 |
|
renamed build_query to creat...
|
1101 |
# Execute SQL with hash binding and filtering |
added insert, update, update...
|
1102 |
$dbi->execute("select id from book where {= author} and {like title}", |
removed register_format()
|
1103 |
param => {author => 'ken', title => '%Perl%'}, |
renamed dbi_options to dbi_o...
|
1104 |
filter => {title => 'to_something'}); |
removed reconnect method
|
1105 | |
1106 |
# Create query and execute it |
|
renamed build_query to creat...
|
1107 |
my $query = $dbi->create_query( |
added insert, update, update...
|
1108 |
"select id from book where {= author} and {like title}" |
removed reconnect method
|
1109 |
); |
updated document
|
1110 |
$dbi->execute($query, param => {author => 'Ken', title => '%Perl%'}) |
cleanup
|
1111 | |
1112 |
# Get DBI object |
|
1113 |
my $dbh = $dbi->dbh; |
|
1114 | ||
removed register_format()
|
1115 |
# Fetch |
1116 |
while (my $row = $result->fetch) { |
|
1117 |
# ... |
|
1118 |
} |
|
1119 |
|
|
1120 |
# Fetch hash |
|
1121 |
while (my $row = $result->fetch_hash) { |
|
1122 |
|
|
1123 |
} |
|
1124 |
|
|
renamed update tag to update...
|
1125 |
=head1 DESCRIPTIONS |
removed reconnect method
|
1126 | |
renamed build_query to creat...
|
1127 |
L<DBIx::Custom> is one of L<DBI> interface modules, |
1128 |
such as L<DBIx::Class>, L<DBIx::Simple>. |
|
removed reconnect method
|
1129 | |
renamed build_query to creat...
|
1130 |
This module is not O/R mapper. O/R mapper is useful, |
1131 |
but you must learn many syntax of the O/R mapper, |
|
updated document
|
1132 |
which is almost another language. |
1133 |
Created SQL statement is offten not effcient and damage SQL performance. |
|
renamed build_query to creat...
|
1134 |
so you have to execute raw SQL in the end. |
removed reconnect method
|
1135 | |
renamed build_query to creat...
|
1136 |
L<DBIx::Custom> is middle area between L<DBI> and O/R mapper. |
updated document
|
1137 |
L<DBIx::Custom> provide flexible hash parameter binding and filtering system, |
added experimental expand me...
|
1138 |
and suger methods, such as C<insert()>, C<update()>, C<delete()>, C<select()> |
updated document
|
1139 |
to execute SQL easily. |
removed reconnect method
|
1140 | |
updated document
|
1141 |
L<DBIx::Custom> respects SQL. SQL is very complex and not beautiful, |
1142 |
but de-facto standard, |
|
1143 |
so all people learing database know it. |
|
renamed update tag to update...
|
1144 |
If you already know SQL, |
1145 |
you learn a little thing to use L<DBIx::Custom>. |
|
removed reconnect method
|
1146 | |
pod fix
|
1147 |
See L<DBIx::Custom::Guide> for more details. |
1148 | ||
1149 |
=head1 GUIDE |
|
1150 | ||
1151 |
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide |
|
1152 | ||
1153 |
=head1 EXAMPLES |
|
1154 | ||
1155 |
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> - Many useful examples |
|
updated document
|
1156 | |
update document
|
1157 |
=head1 ATTRIBUTES |
packaging one directory
|
1158 | |
cleanup
|
1159 |
=head2 C<cache> |
packaging one directory
|
1160 | |
cleanup
|
1161 |
my $cache = $dbi->cache; |
1162 |
$dbi = $dbi->cache(1); |
|
removed DESTROY method(not b...
|
1163 | |
cleanup
|
1164 |
Enable parsed L<DBIx::Custom::Query> object caching. |
1165 |
Default to 1. |
|
packaging one directory
|
1166 | |
removed DBIx::Custom commit ...
|
1167 |
=head2 C<data_source> |
packaging one directory
|
1168 | |
cleanup
|
1169 |
my $data_source = $dbi->data_source; |
cleanup
|
1170 |
$dbi = $dbi->data_source("DBI:mysql:database=dbname"); |
removed DESTROY method(not b...
|
1171 | |
cleanup
|
1172 |
Data source. |
1173 |
C<connect()> method use this value to connect the database. |
|
removed DESTROY method(not b...
|
1174 | |
removed DBIx::Custom commit ...
|
1175 |
=head2 C<dbh> |
packaging one directory
|
1176 | |
cleanup
|
1177 |
my $dbh = $dbi->dbh; |
1178 |
$dbi = $dbi->dbh($dbh); |
|
packaging one directory
|
1179 | |
cleanup
|
1180 |
L<DBI> object. You can call all methods of L<DBI>. |
packaging one directory
|
1181 | |
renamed dbi_options to dbi_o...
|
1182 |
=head2 C<dbi_option> |
added dbi_options attribute
|
1183 | |
renamed dbi_options to dbi_o...
|
1184 |
my $dbi_option = $dbi->dbi_option; |
1185 |
$dbi = $dbi->dbi_option($dbi_option); |
|
added dbi_options attribute
|
1186 | |
1187 |
DBI options. |
|
add default_dbi_option()
|
1188 | |
1189 |
Each option specified can ovewrite C<default_dbi_option>. |
|
1190 | ||
1191 |
C<connect()> method use this value to connect the database. |
|
1192 | ||
1193 | ||
1194 |
=head2 C<default_dbi_option> |
|
1195 | ||
1196 |
my $default_dbi_option = $dbi->default_dbi_option; |
|
1197 |
$dbi = $dbi->default_dbi_option($default_dbi_option); |
|
1198 | ||
1199 |
DBI default options. |
|
1200 | ||
1201 |
RaiseError => 1, |
|
1202 |
PrintError => 0, |
|
1203 |
AutoCommit => 1, |
|
1204 | ||
added dbi_options attribute
|
1205 |
C<connect()> method use this value to connect the database. |
1206 | ||
cleanup
|
1207 |
Default filter when row is fetched. |
packaging one directory
|
1208 | |
cleanup
|
1209 |
=head2 C<filters> |
bind_filter argument is chan...
|
1210 | |
cleanup
|
1211 |
my $filters = $dbi->filters; |
1212 |
$dbi = $dbi->filters(\%filters); |
|
packaging one directory
|
1213 | |
add models() attribute
|
1214 |
Filters |
1215 | ||
1216 |
=head2 C<(experimental) models> |
|
1217 | ||
1218 |
my $models = $dbi->models; |
|
1219 |
$dbi = $dbi->models(\%models); |
|
1220 | ||
1221 |
Models |
|
1222 | ||
cleanup
|
1223 |
=head2 C<password> |
1224 | ||
1225 |
my $password = $dbi->password; |
|
1226 |
$dbi = $dbi->password('lkj&le`@s'); |
|
1227 | ||
1228 |
Password. |
|
1229 |
C<connect()> method use this value to connect the database. |
|
update document
|
1230 | |
renamed update tag to update...
|
1231 |
=head2 C<query_builder> |
added commit method
|
1232 | |
renamed update tag to update...
|
1233 |
my $sql_class = $dbi->query_builder; |
1234 |
$dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new); |
|
added commit method
|
1235 | |
renamed update tag to update...
|
1236 |
SQL builder. C<query_builder()> must be |
renamed build_query to creat...
|
1237 |
the instance of L<DBIx::Custom::QueryBuilder> subclass. |
1238 |
Default to L<DBIx::Custom::QueryBuilder> object. |
|
cleanup
|
1239 | |
cleanup
|
1240 |
=head2 C<result_class> |
cleanup
|
1241 | |
cleanup
|
1242 |
my $result_class = $dbi->result_class; |
1243 |
$dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
cleanup
|
1244 | |
cleanup
|
1245 |
Result class for select statement. |
1246 |
Default to L<DBIx::Custom::Result>. |
|
cleanup
|
1247 | |
update pod
|
1248 |
=head2 C<(experimental) safety_column_name> |
1249 | ||
1250 |
my $safety_column_name = $self->safety_column_name; |
|
1251 |
$dbi = $self->safety_column_name($name); |
|
1252 | ||
1253 |
Safety column name regex. |
|
1254 |
Default is qr/^[\w\.]*$/ |
|
1255 | ||
cleanup
|
1256 |
=head2 C<user> |
cleanup
|
1257 | |
cleanup
|
1258 |
my $user = $dbi->user; |
1259 |
$dbi = $dbi->user('Ken'); |
|
cleanup
|
1260 | |
cleanup
|
1261 |
User name. |
1262 |
C<connect()> method use this value to connect the database. |
|
update pod
|
1263 | |
cleanup
|
1264 |
=head1 METHODS |
added commit method
|
1265 | |
cleanup
|
1266 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
autoload DBI method
|
1267 |
and use all method of L<DBI> |
cleanup
|
1268 |
and implements the following new ones. |
added check_filter attribute
|
1269 | |
cleanup
|
1270 |
=head2 C<(experimental) apply_filter> |
added auto_filter method
|
1271 | |
renamed auto_filter to apply...
|
1272 |
$dbi->apply_filter( |
added auto_filter method
|
1273 |
$table, |
fix bug : filter can't over...
|
1274 |
$column1 => {in => $infilter1, out => $outfilter1, end => $endfilter1} |
1275 |
$column2 => {in => $infilter2, out => $outfilter2, end =. $endfilter2} |
|
renamed auto_filter to apply...
|
1276 |
..., |
added auto_filter method
|
1277 |
); |
1278 | ||
renamed auto_filter to apply...
|
1279 |
C<apply_filter> is automatically filter for columns of table. |
added auto_filter method
|
1280 |
This have effect C<insert>, C<update>, C<delete>. C<select> |
cleanup
|
1281 |
and L<DBIx::Custom::Result> object. but this has'nt C<execute> method. |
1282 | ||
cleanup
|
1283 |
If you want to have effect C<execute()> method, use C<table> |
cleanup
|
1284 |
arguments. |
added auto_filter method
|
1285 | |
cleanup
|
1286 |
$result = $dbi->execute( |
1287 |
"select * from table1 where {= key1} and {= key2};", |
|
1288 |
param => {key1 => 1, key2 => 2}, |
|
renamed auto_filter to apply...
|
1289 |
table => ['table1'] |
cleanup
|
1290 |
); |
fix bug : filter can't over...
|
1291 | |
1292 |
You can use three name as column name. |
|
1293 | ||
1294 |
1. column : author |
|
1295 |
2. table.column : book.author |
|
1296 |
3. table__column : book__author |
|
1297 | ||
removed DBIx::Custom commit ...
|
1298 |
=head2 C<connect> |
packaging one directory
|
1299 | |
cleanup
|
1300 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
update document
|
1301 |
user => 'ken', password => '!LFKD%$&'); |
bind_filter argument is chan...
|
1302 | |
cleanup
|
1303 |
Create a new L<DBIx::Custom> object and connect to the database. |
renamed build_query to creat...
|
1304 |
L<DBIx::Custom> is a wrapper of L<DBI>. |
cleanup
|
1305 |
C<AutoCommit> and C<RaiseError> options are true, |
renamed build_query to creat...
|
1306 |
and C<PrintError> option is false by default. |
packaging one directory
|
1307 | |
cleanup
|
1308 |
=head2 C<create_query> |
1309 |
|
|
1310 |
my $query = $dbi->create_query( |
|
added insert, update, update...
|
1311 |
"select * from book where {= author} and {like title};" |
cleanup
|
1312 |
); |
update document
|
1313 | |
cleanup
|
1314 |
Create the instance of L<DBIx::Custom::Query> from the source of SQL. |
1315 |
If you want to get high performance, |
|
1316 |
use C<create_query()> method and execute it by C<execute()> method |
|
1317 |
instead of suger methods. |
|
bind_filter argument is chan...
|
1318 | |
cleanup
|
1319 |
$dbi->execute($query, {author => 'Ken', title => '%Perl%'}); |
version 0.0901
|
1320 | |
cleanup
|
1321 |
=head2 C<execute> |
packaging one directory
|
1322 | |
cleanup
|
1323 |
my $result = $dbi->execute($query, param => $params, filter => \%filter); |
1324 |
my $result = $dbi->execute($source, param => $params, filter => \%filter); |
|
update document
|
1325 | |
cleanup
|
1326 |
Execute query or the source of SQL. |
1327 |
Query is L<DBIx::Custom::Query> object. |
|
1328 |
Return value is L<DBIx::Custom::Result> if select statement is executed, |
|
1329 |
or the count of affected rows if insert, update, delete statement is executed. |
|
version 0.0901
|
1330 | |
removed DBIx::Custom commit ...
|
1331 |
=head2 C<delete> |
packaging one directory
|
1332 | |
cleanup
|
1333 |
$dbi->delete(table => $table, |
1334 |
where => \%where, |
|
1335 |
append => $append, |
|
added experimental sugar met...
|
1336 |
filter => \%filter, |
1337 |
query => 1); |
|
bind_filter argument is chan...
|
1338 | |
renamed build_query to creat...
|
1339 |
Execute delete statement. |
1340 |
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments. |
|
1341 |
C<table> is a table name. |
|
1342 |
C<where> is where clause. this must be hash reference. |
|
1343 |
C<append> is a string added at the end of the SQL statement. |
|
1344 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1345 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1346 |
default to 0. This is experimental. |
|
cleanup
|
1347 |
Return value of C<delete()> is the count of affected rows. |
renamed build_query to creat...
|
1348 | |
removed DBIx::Custom commit ...
|
1349 |
=head2 C<delete_all> |
packaging one directory
|
1350 | |
cleanup
|
1351 |
$dbi->delete_all(table => $table); |
packaging one directory
|
1352 | |
renamed build_query to creat...
|
1353 |
Execute delete statement to delete all rows. |
1354 |
Arguments is same as C<delete> method, |
|
1355 |
except that C<delete_all> don't have C<where> argument. |
|
cleanup
|
1356 |
Return value of C<delete_all()> is the count of affected rows. |
bind_filter argument is chan...
|
1357 | |
add experimental update_at()...
|
1358 |
=head3 C<delete_at()> |
1359 | ||
1360 |
To delete row by using primary key, use C<delete_at()> |
|
1361 | ||
1362 |
$dbi->delete_at( |
|
1363 |
table => 'book', |
|
1364 |
primary_key => ['id'], |
|
1365 |
where => ['123'] |
|
1366 |
); |
|
1367 | ||
1368 |
In this example, row which id column is 123 is deleted. |
|
1369 |
NOTE that you must pass array reference as C<where>. |
|
1370 | ||
1371 |
You can also write arguments like this. |
|
1372 | ||
1373 |
$dbi->delete_at( |
|
1374 |
table => 'book', |
|
1375 |
primary_key => ['id'], |
|
1376 |
param => {id => '123'} |
|
1377 |
); |
|
1378 | ||
cleanup
|
1379 |
=head2 C<insert> |
1380 | ||
1381 |
$dbi->insert(table => $table, |
|
1382 |
param => \%param, |
|
1383 |
append => $append, |
|
added experimental sugar met...
|
1384 |
filter => \%filter, |
1385 |
query => 1); |
|
cleanup
|
1386 | |
1387 |
Execute insert statement. |
|
1388 |
C<insert> method have C<table>, C<param>, C<append> |
|
1389 |
and C<filter> arguments. |
|
1390 |
C<table> is a table name. |
|
1391 |
C<param> is the pairs of column name value. this must be hash reference. |
|
1392 |
C<append> is a string added at the end of the SQL statement. |
|
1393 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1394 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1395 |
default to 0. This is experimental. |
|
cleanup
|
1396 |
This is overwrites C<default_bind_filter>. |
1397 |
Return value of C<insert()> is the count of affected rows. |
|
1398 | ||
pod fix
|
1399 |
=head2 C<(experimental) each_column> |
added experimental iterate_a...
|
1400 | |
pod fix
|
1401 |
$dbi->each_column( |
added experimental iterate_a...
|
1402 |
sub { |
add experimental setup_model...
|
1403 |
my ($self, $table, $column, $column_info) = @_; |
added experimental iterate_a...
|
1404 |
|
add experimental setup_model...
|
1405 |
my $type = $column_info->{TYPE_NAME}; |
pod fix
|
1406 |
|
1407 |
if ($type eq 'DATE') { |
|
1408 |
# ... |
|
1409 |
} |
|
added experimental iterate_a...
|
1410 |
} |
1411 |
); |
|
pod fix
|
1412 |
Get column informations from database. |
1413 |
Argument is callback. |
|
1414 |
You can do anything in callback. |
|
added experimental not_exist...
|
1415 |
Callback receive four arguments, dbi object, table name, |
add experimental setup_model...
|
1416 |
column name and column information. |
added experimental not_exist...
|
1417 | |
add feture. all model class ...
|
1418 |
=head2 C<(experimental) include_model> |
removed experimental base_ta...
|
1419 | |
add feture. all model class ...
|
1420 |
$dbi->include_model( |
1421 |
'MyModel' => [ |
|
removed experimental base_ta...
|
1422 |
'book', 'person', 'company' |
1423 |
] |
|
1424 |
); |
|
1425 | ||
add feture. all model class ...
|
1426 |
Include models. First argument is name space. |
removed experimental base_ta...
|
1427 |
Second argument is array reference of class base names. |
1428 | ||
add feture. all model class ...
|
1429 |
If you don't specify second argument, All models under name space is |
1430 |
included. |
|
1431 | ||
1432 |
$dbi->include_model('MyModel'); |
|
1433 | ||
1434 |
Note that in this case name spece module is needed. |
|
1435 | ||
1436 |
# MyModel.pm |
|
1437 |
package MyModel; |
|
1438 |
|
|
1439 |
use base 'DBIx::Custom::Model'; |
|
1440 | ||
1441 |
The following model is instantiated and included. |
|
removed experimental base_ta...
|
1442 | |
add feture. all model class ...
|
1443 |
MyModel::book |
1444 |
MyModel::person |
|
1445 |
MyModel::company |
|
removed experimental base_ta...
|
1446 | |
add feture. all model class ...
|
1447 |
You can get these instance by C<model()>. |
removed experimental base_ta...
|
1448 | |
add feture. all model class ...
|
1449 |
my $book_model = $dbi->model('book'); |
removed experimental base_ta...
|
1450 | |
add feture. all model class ...
|
1451 |
If you want to other name as model class, |
removed experimental base_ta...
|
1452 |
you can do like this. |
1453 | ||
add feture. all model class ...
|
1454 |
$dbi->include_model( |
1455 |
'MyModel' => [ |
|
removed experimental base_ta...
|
1456 |
{'book' => 'Book'}, |
1457 |
{'person' => 'Person'} |
|
1458 |
] |
|
1459 |
); |
|
1460 | ||
added experimental not_exist...
|
1461 |
=head2 C<(experimental) method> |
1462 | ||
1463 |
$dbi->method( |
|
1464 |
update_or_insert => sub { |
|
1465 |
my $self = shift; |
|
1466 |
# do something |
|
1467 |
}, |
|
1468 |
find_or_create => sub { |
|
1469 |
my $self = shift; |
|
1470 |
# do something |
|
1471 |
} |
|
1472 |
); |
|
1473 | ||
1474 |
Register method. These method is called from L<DBIx::Custom> object directory. |
|
1475 | ||
1476 |
$dbi->update_or_insert; |
|
1477 |
$dbi->find_or_create; |
|
1478 | ||
1479 |
=head2 C<new> |
|
1480 | ||
1481 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
|
1482 |
user => 'ken', password => '!LFKD%$&'); |
|
1483 | ||
1484 |
Create a new L<DBIx::Custom> object. |
|
1485 | ||
1486 |
=head2 C<(experimental) not_exists> |
|
1487 | ||
1488 |
my $not_exists = $dbi->not_exists; |
|
1489 | ||
1490 |
Get DBIx::Custom::NotExists object. |
|
experimental extended select...
|
1491 | |
cleanup
|
1492 |
=head2 C<register_filter> |
1493 | ||
1494 |
$dbi->register_filter(%filters); |
|
1495 |
$dbi->register_filter(\%filters); |
|
1496 |
|
|
1497 |
Register filter. Registered filters is available in the following attributes |
|
1498 |
or arguments. |
|
1499 | ||
1500 |
=over 4 |
|
1501 | ||
1502 |
=item * |
|
1503 | ||
1504 |
C<filter> argument of C<insert()>, C<update()>, |
|
1505 |
C<update_all()>, C<delete()>, C<delete_all()>, C<select()> |
|
1506 |
methods |
|
1507 | ||
1508 |
=item * |
|
1509 | ||
1510 |
C<execute()> method |
|
1511 | ||
1512 |
=item * |
|
1513 | ||
1514 |
C<default_filter> and C<filter> of C<DBIx::Custom::Query> |
|
1515 | ||
1516 |
=item * |
|
1517 | ||
1518 |
C<default_filter> and C<filter> of C<DBIx::Custom::Result> |
|
1519 | ||
1520 |
=back |
|
1521 | ||
renamed DBIx::Custom::TagPro...
|
1522 |
=head2 C<register_tag> |
added register_tag_processor
|
1523 | |
renamed DBIx::Custom::TagPro...
|
1524 |
$dbi->register_tag( |
added register_tag_processor
|
1525 |
limit => sub { |
1526 |
...; |
|
1527 |
} |
|
1528 |
); |
|
1529 | ||
cleanup
|
1530 |
Register tag. |
added register_tag_processor
|
1531 | |
added auto_filter method
|
1532 |
=head2 C<rollback> |
cleanup
|
1533 | |
1534 |
$dbi->rollback; |
|
1535 | ||
1536 |
Rollback transaction. |
|
1537 |
This is same as L<DBI>'s C<rollback>. |
|
1538 | ||
removed DBIx::Custom commit ...
|
1539 |
=head2 C<select> |
packaging one directory
|
1540 |
|
cleanup
|
1541 |
my $result = $dbi->select(table => $table, |
1542 |
column => [@column], |
|
1543 |
where => \%where, |
|
1544 |
append => $append, |
|
1545 |
relation => \%relation, |
|
added experimental sugar met...
|
1546 |
filter => \%filter, |
add experimental selection o...
|
1547 |
query => 1, |
1548 |
selection => $selection); |
|
update document
|
1549 | |
renamed build_query to creat...
|
1550 |
Execute select statement. |
cleanup
|
1551 |
C<select> method have C<table>, C<column>, C<where>, C<append>, |
renamed build_query to creat...
|
1552 |
C<relation> and C<filter> arguments. |
1553 |
C<table> is a table name. |
|
cleanup
|
1554 |
C<where> is where clause. this is normally hash reference. |
renamed build_query to creat...
|
1555 |
C<append> is a string added at the end of the SQL statement. |
1556 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1557 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1558 |
default to 0. This is experimental. |
|
add experimental selection o...
|
1559 |
C<selection> is string of column name and tables. This is experimental |
1560 | ||
1561 |
selection => 'name, location.name as location_name ' . |
|
1562 |
'from company inner join location' |
|
update document
|
1563 | |
cleanup
|
1564 |
First element is a string. it contains tags, |
1565 |
such as "{= title} or {like author}". |
|
1566 |
Second element is paramters. |
|
1567 | ||
add experimental update_at()...
|
1568 |
=head3 C<select_at()> |
1569 | ||
1570 |
To select row by using primary key, use C<select_at()>. |
|
1571 | ||
1572 |
$dbi->select_at(table => 'book', primary_key => ['id'], where => ['123']); |
|
1573 | ||
1574 |
In this example, row which id colunm is 123 is selected. |
|
1575 |
NOTE that you must pass array reference as C<where>. |
|
1576 | ||
cleanup
|
1577 |
=head2 C<update> |
removed reconnect method
|
1578 | |
cleanup
|
1579 |
$dbi->update(table => $table, |
1580 |
param => \%params, |
|
1581 |
where => \%where, |
|
1582 |
append => $append, |
|
added experimental sugar met...
|
1583 |
filter => \%filter, |
1584 |
query => 1) |
|
removed reconnect method
|
1585 | |
cleanup
|
1586 |
Execute update statement. |
1587 |
C<update> method have C<table>, C<param>, C<where>, C<append> |
|
1588 |
and C<filter> arguments. |
|
1589 |
C<table> is a table name. |
|
1590 |
C<param> is column-value pairs. this must be hash reference. |
|
1591 |
C<where> is where clause. this must be hash reference. |
|
1592 |
C<append> is a string added at the end of the SQL statement. |
|
1593 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1594 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1595 |
default to 0. This is experimental. |
|
cleanup
|
1596 |
This is overwrites C<default_bind_filter>. |
1597 |
Return value of C<update()> is the count of affected rows. |
|
removed reconnect method
|
1598 | |
add feture. all model class ...
|
1599 |
=head2 C<(experimental) model> |
remove DBIx::Custom::Model
|
1600 | |
add feture. all model class ...
|
1601 |
$dbi->model('book')->method( |
remove DBIx::Custom::Model
|
1602 |
insert => sub { ... }, |
1603 |
update => sub { ... } |
|
1604 |
); |
|
1605 |
|
|
add feture. all model class ...
|
1606 |
my $model = $dbi->model('book'); |
remove DBIx::Custom::Model
|
1607 | |
add feture. all model class ...
|
1608 |
Set and get a L<DBIx::Custom::Model> object, |
remove DBIx::Custom::Model
|
1609 | |
add experimental setup_model...
|
1610 |
=head2 C<(experimental) setup_model> |
1611 | ||
1612 |
$dbi->setup_model; |
|
1613 | ||
1614 |
Setup all model objects. |
|
1615 |
C<columns> and C<primary_key> is automatically set. |
|
1616 | ||
cleanup
|
1617 |
=head2 C<update_all> |
renamed build_query to creat...
|
1618 | |
cleanup
|
1619 |
$dbi->update_all(table => $table, |
1620 |
param => \%params, |
|
1621 |
filter => \%filter, |
|
1622 |
append => $append); |
|
renamed build_query to creat...
|
1623 | |
cleanup
|
1624 |
Execute update statement to update all rows. |
1625 |
Arguments is same as C<update> method, |
|
1626 |
except that C<update_all> don't have C<where> argument. |
|
1627 |
Return value of C<update_all()> is the count of affected rows. |
|
removed DBIx::Custom commit ...
|
1628 | |
add experimental update_at()...
|
1629 |
=head3 C<update_at()> |
1630 | ||
1631 |
To update row by using primary key, use C<update_at()> |
|
1632 | ||
1633 |
$dbi->update_at( |
|
1634 |
table => 'book', |
|
1635 |
primary_key => ['id'], |
|
1636 |
where => ['123'], |
|
1637 |
param => {name => 'Ken'} |
|
1638 |
); |
|
1639 | ||
1640 |
In this example, row which id column is 123 is updated. |
|
1641 |
NOTE that you must pass array reference as C<where>. |
|
1642 |
If C<param> contains primary key, |
|
1643 |
the key and value is delete from C<param>. |
|
1644 | ||
fix tests
|
1645 |
=head2 C<(experimental) where> |
1646 | ||
1647 |
my $where = $dbi->where; |
|
1648 | ||
1649 |
Create a new L<DBIx::Custom::Where> object. |
|
1650 | ||
cleanup
|
1651 |
=head2 C<cache_method> |
cleanup
|
1652 | |
1653 |
$dbi = $dbi->cache_method(\&cache_method); |
|
1654 |
$cache_method = $dbi->cache_method |
|
1655 | ||
1656 |
Method to set and get caches. |
|
1657 | ||
cleanup
|
1658 |
=head1 Tags |
1659 | ||
1660 |
The following tags is available. |
|
1661 | ||
add experimental selection o...
|
1662 |
=head2 C<(experimental) table> |
add table tag
|
1663 | |
1664 |
Table tag |
|
1665 | ||
1666 |
{table TABLE} -> TABLE |
|
1667 | ||
1668 |
This is used to teach what is applied table to C<execute()>. |
|
1669 | ||
cleanup
|
1670 |
=head2 C<?> |
1671 | ||
1672 |
Placeholder tag. |
|
1673 | ||
1674 |
{? NAME} -> ? |
|
1675 | ||
1676 |
=head2 C<=> |
|
1677 | ||
1678 |
Equal tag. |
|
1679 | ||
1680 |
{= NAME} -> NAME = ? |
|
1681 | ||
1682 |
=head2 C<E<lt>E<gt>> |
|
1683 | ||
1684 |
Not equal tag. |
|
1685 | ||
1686 |
{<> NAME} -> NAME <> ? |
|
1687 | ||
1688 |
=head2 C<E<lt>> |
|
1689 | ||
1690 |
Lower than tag |
|
1691 | ||
1692 |
{< NAME} -> NAME < ? |
|
1693 | ||
1694 |
=head2 C<E<gt>> |
|
1695 | ||
1696 |
Greater than tag |
|
1697 | ||
1698 |
{> NAME} -> NAME > ? |
|
1699 | ||
1700 |
=head2 C<E<gt>=> |
|
1701 | ||
1702 |
Greater than or equal tag |
|
1703 | ||
1704 |
{>= NAME} -> NAME >= ? |
|
1705 | ||
1706 |
=head2 C<E<lt>=> |
|
1707 | ||
1708 |
Lower than or equal tag |
|
1709 | ||
1710 |
{<= NAME} -> NAME <= ? |
|
1711 | ||
1712 |
=head2 C<like> |
|
1713 | ||
1714 |
Like tag |
|
1715 | ||
1716 |
{like NAME} -> NAME like ? |
|
1717 | ||
1718 |
=head2 C<in> |
|
1719 | ||
1720 |
In tag. |
|
1721 | ||
1722 |
{in NAME COUNT} -> NAME in [?, ?, ..] |
|
1723 | ||
1724 |
=head2 C<insert_param> |
|
1725 | ||
1726 |
Insert parameter tag. |
|
1727 | ||
1728 |
{insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
|
1729 | ||
1730 |
=head2 C<update_param> |
|
1731 | ||
1732 |
Updata parameter tag. |
|
1733 | ||
1734 |
{update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
|
1735 | ||
DBIx::Custom is now stable
|
1736 |
=head1 STABILITY |
1737 | ||
cleanup
|
1738 |
L<DBIx::Custom> is stable. APIs keep backword compatible |
1739 |
except experimental one in the feature. |
|
DBIx::Custom is now stable
|
1740 | |
removed DESTROY method(not b...
|
1741 |
=head1 BUGS |
1742 | ||
renamed build_query to creat...
|
1743 |
Please tell me bugs if found. |
removed DESTROY method(not b...
|
1744 | |
1745 |
C<< <kimoto.yuki at gmail.com> >> |
|
1746 | ||
1747 |
L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
1748 | ||
removed reconnect method
|
1749 |
=head1 AUTHOR |
1750 | ||
1751 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
version 0.0901
|
1752 | |
packaging one directory
|
1753 |
=head1 COPYRIGHT & LICENSE |
1754 | ||
cleanup
|
1755 |
Copyright 2009-2011 Yuki Kimoto, all rights reserved. |
packaging one directory
|
1756 | |
1757 |
This program is free software; you can redistribute it and/or modify it |
|
1758 |
under the same terms as Perl itself. |
|
1759 | ||
1760 |
=cut |
|
added cache_method attribute
|
1761 | |
1762 |